mirror of
https://github.com/c-cube/tiny_httpd.git
synced 2026-03-07 21:37:57 -05:00
eio: add 60s shutdown backstop, protect Flow.close from raising
This commit is contained in:
parent
3b631b7e4c
commit
c6468dced8
1 changed files with 8 additions and 2 deletions
|
|
@ -173,7 +173,13 @@ let io_backend ?addr ?port ?unix_sock ?max_connections ?max_buf_pool_size
|
||||||
running = (fun () -> Atomic.get running);
|
running = (fun () -> Atomic.get running);
|
||||||
stop =
|
stop =
|
||||||
(fun () ->
|
(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);
|
endpoint = (fun () -> actual_addr, actual_port);
|
||||||
active_connections = (fun () -> Atomic.get active_conns);
|
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");
|
k "Tiny_httpd_eio: client handler returned");
|
||||||
Atomic.decr active_conns;
|
Atomic.decr active_conns;
|
||||||
Eio.Semaphore.release sem;
|
Eio.Semaphore.release sem;
|
||||||
Eio.Flow.close conn)
|
(try Eio.Flow.close conn with Eio.Io _ -> ()))
|
||||||
in
|
in
|
||||||
(try
|
(try
|
||||||
Eio_unix.Fd.use_exn "setsockopt"
|
Eio_unix.Fd.use_exn "setsockopt"
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue