From 6399acc00722caac098ed0e54a16b68eaea4e125 Mon Sep 17 00:00:00 2001 From: mefyl Date: Wed, 7 Feb 2024 15:43:43 +0100 Subject: [PATCH] cohttp-eio.Server: Don't blow up in `callback` on client read timeout. --- CHANGES.md | 1 + cohttp-eio/src/server.ml | 15 ++++++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 0beaf4d54..bdf711db9 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,6 @@ ## Unreleased +- cohttp-eio: Don't blow up `Server.callback` on connection timeout. (mefyl #1021) - cohttp-eio: Don't blow up `Server.callback` on client disconnections. (mefyl #1015) - http: Fix assertion in `Source.to_string_trim` when `pos <> 0` (mefyl #1017) diff --git a/cohttp-eio/src/server.ml b/cohttp-eio/src/server.ml index 364c83385..c73c65e2c 100644 --- a/cohttp-eio/src/server.ml +++ b/cohttp-eio/src/server.ml @@ -103,11 +103,16 @@ let callback { conn_closed; handler } ((_, peer_address) as conn) input output = in conn_closed (conn, id) | exception Eio.Io (Eio.Net.E (Connection_reset _), _) -> - let () = - Logs.info (fun m -> - m "%a: connection reset" Eio.Net.Sockaddr.pp peer_address) - in - () + Logs.info (fun m -> + m "%a: connection reset" Eio.Net.Sockaddr.pp peer_address) + | exception + Eio.Io + ( Eio.Exn.X _ + (* To catch the backend-specific Eio_unix.Unix_error + (ETIMEDOUT, _, _), at least *), + _ ) -> + Logs.info (fun m -> + m "%a: connection timed out" Eio.Net.Sockaddr.pp peer_address) | `Invalid e -> write output (Http.Response.make ~status:`Bad_request ())