Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Force users to give a custom callback in case of exception to avoid random crashes #261

Merged
merged 1 commit into from
Aug 17, 2019

Conversation

kit-ty-kate
Copy link
Contributor

When using Conduit_lwt_unix.serve with cohttp, for instance, in a very simple http server that serves files, the server crashes with an exception when the connexion is cut while the server is trying to send the response. For example this happens very frequently if you are spamming Ctrl-R on your browser.

This happens because the on_exn parameter defaults to print an error message with a backtrace if available and to exit the program (quote from the Lwt.async_exception_hook documentation).

My proposal is simple: it is really easy to make this mistake, the error is quite difficult to understand and might happens at any moment, and therefore the user should be forced to choose what to do in case an exception is raised.

cc @rgrinberg

@avsm
Copy link
Member

avsm commented Oct 19, 2018

This looks fine; I'll do it as a separate release due to the interface bump however.

@mseri
Copy link

mseri commented Oct 25, 2018

Can you also send a PR to update https://github.com/mirage/ocaml-cohttp/blob/master/cohttp-lwt-unix/src/server.ml#L56 and the corresponding mli (to be merged in parallel with this and released after this)? In there is maybe worth to add an example, e.g. the one suggested in mirage/ocaml-cohttp#511

let on_exn = function
  | Unix.Unix_error (error, func, arg) ->
    Logs.warn (fun m ->
      m  "Client connection error %s: %s(%S)"
        (Unix.error_message error) func arg
    )
  | exn -> Logs.err (fun m -> m "Unhandled exception: %a" Fmt.exn exn)
)

just to point out what it could look like, or maybe even add something like that as the default, to make the behaviour slightly saner

@mseri
Copy link

mseri commented Jul 16, 2019

What's the status of this? I think this is a welcome change to have

@avsm avsm merged commit 07a1925 into mirage:master Aug 17, 2019
avsm added a commit to avsm/opam-repository that referenced this pull request Aug 17, 2019
… conduit-lwt-unix (2.0.0)

CHANGES:

* lwt-unix: obtain client IP correctly when using TLS connections (mirage/ocaml-conduit#277 @victorgomes)
* lwt-unix: replace the dune/ocaml file with a `(select)` build form.
  This avoids invoking `ocamlfind` from the build, and fits in with the
  rest of dune builds much more naturally (@avsm).
* lwt-unix: force callers to give a custom callback `on_exn` in case of exceptions
  to avoid random crashes (mirage/ocaml-conduit#261 @kit-ty-kate)
* mirage: use `dns-client>=4.0.0` which is the `udns` implementation (mirage/ocaml-conduit#290 @hannesm)
* mirage: rename `mirage-conduit` to `conduit-mirage` to fit the naming structure
  of this library suite more.  All new users of Mirage should use `conduit-mirage`,
  and migrating should involve simply swapping the name in your `dune` and `opam`
  files (mirage/ocaml-conduit#302 @hannesm @avsm)
* async: expose `verify_mode` correctly in `Conduit_async` (mirage/ocaml-conduit#298 @brendanlong)
kit-ty-kate added a commit to kit-ty-kate/mirage-ci that referenced this pull request Jun 24, 2020
kit-ty-kate added a commit to kit-ty-kate/mirage-ci that referenced this pull request Jun 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants