vdoc: add http connection read/write timeouts (fix #7343)

pull/7351/head
Delyan Angelov 2020-12-15 17:12:33 +02:00
parent e40e1500a8
commit a4d3a0575a
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
2 changed files with 6 additions and 1 deletions

View File

@ -175,6 +175,8 @@ fn (mut cfg DocConfig) serve_html() {
server.close() or { } server.close() or { }
panic(err) panic(err)
} }
conn.set_read_timeout(5 * time.second)
conn.set_write_timeout(5 * time.second)
handle_http_connection(mut conn, server_context) handle_http_connection(mut conn, server_context)
conn.close() or { eprintln('error closing the connection: $err') } conn.close() or { eprintln('error closing the connection: $err') }
} }

View File

@ -48,9 +48,11 @@ fn (mut r BufferedReader) fill_buffer() ? {
// from the upstream reader so that we dont have to keep // from the upstream reader so that we dont have to keep
// trying to call this // trying to call this
r.offset = 0 r.offset = 0
r.len = r.reader.read(mut r.buf) or { new_len := r.reader.read(mut r.buf) or {
eprintln('>> BufferedReader.reader.read err: $err')
0 0
} }
r.len = new_len
} }
// read_line reads a line from the buffered reader // read_line reads a line from the buffered reader
@ -93,3 +95,4 @@ pub fn (mut r BufferedReader) read_line() ?string {
r.offset = i r.offset = i
} }
} }