vweb,net: just log errors in accept() instead of panic-ing, add time.sleep(1ms) after each retry in select (#10489)

pull/10493/head
Tomas Hellström 2021-06-17 09:41:26 +02:00 committed by GitHub
parent c2a7a84c72
commit 46eb6befd5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 3 deletions

View File

@ -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
}

View File

@ -333,7 +333,11 @@ pub fn run<T>(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<T>(mut conn, mut request_app)
}
}