-
Notifications
You must be signed in to change notification settings - Fork 44
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
Expose a way to flush writes in Websocket_lwt_unix
#132
Comments
I looked at Lwt code and it looks you're right, I now use another library (https://github.com/deepmarker/ocaml-fastws) for my websocket needs (Async only, I never made a release but it has been working satisfactorily for years in prod), hence I'm not familiar with ocaml-websocket anymore. But I think flushing should be the default. Any opinion @copy @paurkedal ? |
I'm personally happy with that - I was going to do that in my application anyway (
In a sense, I was surprised by the behaviour as well and it took me a while what was wrong with the code. In a different sense, what would have been the point of |
It's fine not to flush after a |
I agree it is better to auto-flush there, since the content is already buffered. (Apropos the question of returning a promise, the reason it may be needed even if the write function is not flushing, would be to ensure a fixed upper size on buffering. It's not so relevant when the protocol uses fixed frames, though.) |
Thanks @vbmithr and @paurkedal! |
I am writing a websocket client-server pair and found that when my server crashed (due to my own mistakes) the client would keep "writing" as if the server was still receiving data. By using
strace
, I could see that thewrite
syscalls on the client were returningEPIPE
, yet no exceptions were being raised anywhere that my code could catch and handle.After some debugging, I have found that it's due to
Lwt_io.write
s being buffered. TheLwt_io.write
will (most of the time) not write to the socket. The writes will be flushed "in the background", and so will not be reported as a failure of this promise. In order to be able to handle the write error, I'd like to be able to explicitly flush the underlyingLwt_io.oc
. I guess I would just add a:to the
Websocket_lwt_unix
module. Do you think this is a reasonable change? I'm willing to make the contribution if so.The text was updated successfully, but these errors were encountered: