Skip to content

Commit

Permalink
cohttp-eio: Improve error handling in example server
Browse files Browse the repository at this point in the history
The example was using `~on_error:raise`, which causes the server to
crash if any error occurs handling a connection. This is unlikely to be
what you want. Instead, log the error and continue.

This also now matches the behaviour of the Lwt example, which just logs
errors and continues.
  • Loading branch information
talex5 committed Feb 27, 2024
1 parent 6ed9bae commit 034aba8
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## Unreleased

- cohttp-eio: Improve error handling in example server (talex5 #1023)
- 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)

Expand Down
3 changes: 2 additions & 1 deletion cohttp-eio/examples/server1.ml
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,5 @@ let () =
Eio.Net.listen env#net ~sw ~backlog:128 ~reuse_addr:true
(`Tcp (Eio.Net.Ipaddr.V4.loopback, !port))
and server = Cohttp_eio.Server.make ~callback:handler () in
Cohttp_eio.Server.run socket server ~on_error:raise
Cohttp_eio.Server.run socket server
~on_error:(fun ex -> Logs.warn (fun f -> f "%a" Eio.Exn.pp ex))

0 comments on commit 034aba8

Please sign in to comment.