From 46eb6befd5fb4e905f48a6808a9ab154bbd0e17e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomas=20Hellstr=C3=B6m?= Date: Thu, 17 Jun 2021 09:41:26 +0200 Subject: [PATCH] vweb,net: just log errors in accept() instead of panic-ing, add time.sleep(1ms) after each retry in select (#10489) --- vlib/net/common.v | 7 +++++-- vlib/vweb/vweb.v | 6 +++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/vlib/net/common.v b/vlib/net/common.v index 69586ffaa4..da2ee28047 100644 --- a/vlib/net/common.v +++ b/vlib/net/common.v @@ -71,11 +71,14 @@ fn @select(handle int, test Select, timeout time.Duration) ?bool { // collection [inline] fn select_with_retry(handle int, test Select, timeout time.Duration) ?bool { - mut retries := 3 + mut retries := 10 for retries > 0 { ready := @select(handle, test, timeout) or { if err.code == 4 { - // signal! lets retry max 3 times + // signal! lets retry max 10 times + // suspend thread with sleep to let the gc get + // cycles in the case the Bohem gc is interupting + time.sleep(1 * time.millisecond) retries -= 1 continue } diff --git a/vlib/vweb/vweb.v b/vlib/vweb/vweb.v index 70f2432707..a3b739dc7c 100644 --- a/vlib/vweb/vweb.v +++ b/vlib/vweb/vweb.v @@ -333,7 +333,11 @@ pub fn run(global_app &T, port int) { // request_app.Context = Context{ // conn: 0 //} - mut conn := l.accept() or { panic('accept() failed') } + mut conn := l.accept() or { + // failures should not panic + eprintln('accept() failed with error: $err.msg') + continue + } go handle_conn(mut conn, mut request_app) } }