You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi! I want to write recv code with timeouts like this (just synthetic example):
open Lwt
...
let myrecv ~timeout conn =
let action_th = Websocket_lwt_unix.read conn >>= fun x -> return (Some x) in
let timeout_th = Lwt_unix.sleep timeout >>= fun () -> return None in
Lwt.pick [ timeout_th ; action_th ]
...
myrecv ~timeout:3.0 >>= function
| None -> (* TODO: do something else and try again *)
| Some x -> ...
I am not sure this would be a reliable way of implementing a timeout. If the cancel happens in between the individual read operations in websocket.read_frame, will we not end up with an out of sync stream on the input channel, from which it will be hard to recover?
Not sure what does "out of sync stream" mean - you mean that we can loose some frames? For now if Lwt.cancel happens - we have invalid connection - with working fine write socket oc and closed read socket ic (and when we try to read from closed socket we get End_of_file exception)
If you look at core/websocket.ml starting at line 278, the invocation of read_uint16 or read_uint64 is followed by two read_exactly. If the cancel happens before either of the two read_exactly, there will be bytes left on ic from that frame, which need to be discarded before processing the next frame.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hi! I want to write recv code with timeouts like this (just synthetic example):
Could you please consider this PR
@vbmithr @paurkedal