Description
Please bear with me as I'm new to OCaml and the whole ecosystem. Currently using websocket_async
.
The current implementation seems to raise an exception whenever a client disconnects. This can be easily reproduced with wscat-async
on master as follows:
A server:
> ./wscat.exe -s ws://localhost:9999
Client
> ./wscat.exe ws://localhost:9999/ws
Then press Control-C
on the client.
The output of the server:
2020-04-13 22:02:12.066187+01:00 Error ("Exception raised to [Monitor.try_with] that already returned.""This error was captured by a default handler in [Async.Log]."(exn(monitor.ml.Error End_of_file("Raised at file \"core/websocket.ml\", line 268, characters 14-31""Called from file \"src/deferred0.ml\", line 54, characters 64-69""Called from file \"src/job_queue.ml\", line 167, characters 6-47""Caught by monitor Monitor.protect"))))
Which points to
ocaml-websocket/core/websocket.ml
Line 268 in 49e991b
I guess it can make sense to raise an exception there, however (and this is what caught my attention), the async
implementation also propagates the exception back to the caller as seen in:
ocaml-websocket/async/websocket_async.ml
Lines 287 to 298 in 49e991b
Monitor.protect
propagates)
The server
function returns an 'a Async.Deferred.Or_error.t
but according to the documentation for Async_kernel__.Deferred_or_error the idiom is to never raise:
The mental model for a function returning an 'a Deferred.Or_error.t is that the function never raises. All error cases are caught and expressed as an Error _ result. This module preserves that property.
Should protect
be changed for a try_with_or_error
?