-
Notifications
You must be signed in to change notification settings - Fork 31
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
socket closes too early on sync writes #13
Comments
After some investigation I found that the reason this is happening is because the |
yeah, tcp streams have the allowHalfOpen feature but websockets don't have a thing like that. the trouble is that websockets don't have a kind of "end" message, so you (unfortunately) need to add something to the protocol. It's exactly like a telephone, there is a module for that! https://github.com/dominictarr/pull-goodbye you could use that, or, in this case, the bulk encryption protocol (for the body of the session, after the handshake) ought to have a way to signal a correct end, for example pull-box-stream ends in a zero length packet https://github.com/dominictarr/pull-box-stream#protocol-1 |
sorry, I didn't read your post properly - this is just about ensuring the data is actually sent... there is no callback for that, though, so we'd have to poll it ); |
Thanks a lot @dominictarr! My issue was with both things you mentioned, the first problem with the "halfOpen" connection and the other with concern about ensuring the data is actually sent before we close the connection. |
This issue is similar to the one we have in
I really much prefer to close gracefully a connection if we can do it in that way. To implement that, we need to add a special 'packet' to signal the FIN, which can happen in one of two ways (AFAIK):
In addition to this, every other WebSockets language implementation will need this to be compatible with libp2p, so at that point, better write an RFC for a WebSockets extension. I like the idea of the simple extension and wrapping the packets. Note: it doesn't have to happen on |
@diasdavid it really just sounds like |
@whyrusleeping that does not answer the question about what to do with websockets though |
@dignifiedquire hrm, i'm not really sure if i have any valuable input here. in go when you write, you will get an error if the write failed. You will also fail to write if the other side has closed their end of the connection. |
websockets already have framing - would it be possible to just send a zero length message? (just an idea, I am not sure whether websockets let you do this) |
When running a server in node like this
and a client like this
It fails, with the
result
being equal to only the first element in the series. If I uncomment thedelay
it works as expected.I took the
delay
definition out of the tests in here, so it seems this is somewhat known, but it still is a problem for me.I looked at the traffic in the browser and all things are sent and received, just the pull-stream itself is aborted without forwarding all the messages.
The text was updated successfully, but these errors were encountered: