From c6468dced849bc4c145c3533e46902f247ca163b Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Sun, 15 Feb 2026 21:26:25 +0000 Subject: [PATCH] eio: add 60s shutdown backstop, protect Flow.close from raising --- src/eio/tiny_httpd_eio.ml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/eio/tiny_httpd_eio.ml b/src/eio/tiny_httpd_eio.ml index 85c8d4c9..d7ddba57 100644 --- a/src/eio/tiny_httpd_eio.ml +++ b/src/eio/tiny_httpd_eio.ml @@ -173,7 +173,13 @@ let io_backend ?addr ?port ?unix_sock ?max_connections ?max_buf_pool_size running = (fun () -> Atomic.get running); stop = (fun () -> - Atomic.set running false); + Atomic.set running false; + (* Backstop: fail the switch after 60s if handlers don't complete *) + Eio.Fiber.fork_daemon ~sw (fun () -> + Eio.Time.sleep clock 60.0; + if Eio.Switch.get_error sw |> Option.is_none then + Eio.Switch.fail sw Exit; + `Stop_daemon)); endpoint = (fun () -> actual_addr, actual_port); active_connections = (fun () -> Atomic.get active_conns); } @@ -197,7 +203,7 @@ let io_backend ?addr ?port ?unix_sock ?max_connections ?max_buf_pool_size k "Tiny_httpd_eio: client handler returned"); Atomic.decr active_conns; Eio.Semaphore.release sem; - Eio.Flow.close conn) + (try Eio.Flow.close conn with Eio.Io _ -> ())) in (try Eio_unix.Fd.use_exn "setsockopt"