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

Better handling of IO errors #669

Merged
merged 3 commits into from
Jul 20, 2019
Merged

Better handling of IO errors #669

merged 3 commits into from
Jul 20, 2019

Conversation

talex5
Copy link
Contributor

@talex5 talex5 commented Jul 18, 2019

Before, if the client closed the connection while we were handling a request, the server would crash (by default, unless the user overrode that using on_exn or changing Lwt's async exception handler). Now, we just log this at info level and continue. Exceptions produced by user code are logged as errors, while other exceptions generated by cohttp call back to the conduit exception handler, as before.

Fixes #511.

I first tried getting the IO operations to return a result and plumbing that through everywhere, but it was very painful and caused lots of API changes. So instead, each IO monad is now expected to include handling of IO errors, and provides a catch operation to expose it. This avoids changes to the core of cohttp. The lwt-unix and mirage implementations both make use of Lwt.fail to carry IO errors.

This PR adds a unit-test to check that the server doesn't crash if the client closes the connection. It also adds checks to some other tests to ensure that no errors or warnings were logged during the test.

talex5 added 3 commits July 17, 2019 16:42
Before, if the client closed the connection while we were handling a
request, the server would crash. Now, we just log this at `info` level
and continue.
@avsm avsm merged commit f349fa7 into mirage:master Jul 20, 2019
@avsm
Copy link
Member

avsm commented Jul 20, 2019

Tested on github and rwo's regression tests also -- thanks for this fix!

avsm added a commit to avsm/opam-repository that referenced this pull request Jul 20, 2019
…ohttp-top, cohttp-async and cohttp-mirage (2.2.0)

CHANGES:

- Previously if the client closed the connection while cohttp was
  handling a request, the server would crash (by default, unless the
  user overrode that using `on_exn` or changing Lwt's async exception
  handler). Now, cohttp will just log this at `info` level and
  continue. Exceptions produced by user code are logged as errors,
  while other exceptions generated by cohttp call back to the conduit
  exception handler, as before. (mirage/ocaml-cohttp#669 @talex5)
@hcarty
Copy link
Contributor

hcarty commented Jul 21, 2019

Thank you for this! I think this makes #645 even more important, so these log messages can be controlled separately by the application.

craigfe added a commit to craigfe/irmin that referenced this pull request Jul 26, 2019
Cohttp server creation now allows passing of an exception handler,
fixing a previous issue where the server would crash on a user-raised
exception.

See: mirage/ocaml-cohttp#669
craigfe added a commit to craigfe/irmin that referenced this pull request Jul 26, 2019
Cohttp server creation now allows passing of an exception handler,
fixing a previous issue where the server would crash on a user-raised
exception.

See: mirage/ocaml-cohttp#669
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.

cohttp server crash when client dies mid-transfer
3 participants