From a4d3a0575aa2d528da3e2f9c79deb6079c30c4ed Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Tue, 15 Dec 2020 17:12:33 +0200 Subject: [PATCH] vdoc: add http connection read/write timeouts (fix #7343) --- cmd/tools/vdoc.v | 2 ++ vlib/io/buffered_reader.v | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/cmd/tools/vdoc.v b/cmd/tools/vdoc.v index 2e80552cb8..b6f897de56 100644 --- a/cmd/tools/vdoc.v +++ b/cmd/tools/vdoc.v @@ -175,6 +175,8 @@ fn (mut cfg DocConfig) serve_html() { server.close() or { } panic(err) } + conn.set_read_timeout(5 * time.second) + conn.set_write_timeout(5 * time.second) handle_http_connection(mut conn, server_context) conn.close() or { eprintln('error closing the connection: $err') } } diff --git a/vlib/io/buffered_reader.v b/vlib/io/buffered_reader.v index c32993d6d3..32616ff888 100644 --- a/vlib/io/buffered_reader.v +++ b/vlib/io/buffered_reader.v @@ -48,9 +48,11 @@ fn (mut r BufferedReader) fill_buffer() ? { // from the upstream reader so that we dont have to keep // trying to call this 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 } + r.len = new_len } // read_line reads a line from the buffered reader @@ -93,3 +95,4 @@ pub fn (mut r BufferedReader) read_line() ?string { r.offset = i } } +