-
Notifications
You must be signed in to change notification settings - Fork 189
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
broken pipe if session is closed "early" #23
Comments
I wrote a test for this. And if you add my modification(see code block above) to I replace everything in Here is the code:
|
https://github.com/xtaci/smux/blob/master/stream.go#L55 are your referring to this ? AFAIK,the behavior of reading after close is not specified in net.Conn. also , it's completly ok to remove this select. |
Yes, exactly. I would expect that the internal buffer of stream would have to be completely read(via With a normal
the client will first receive 50.000 bytes and then the connection will be closed. But with smux it becomes a race because of the multiplexing. The client might receive some data, and then maybe a signal saying the session was closed before the rest of the data has been read/consumed. |
try the commit pls |
Works like a charm for me! |
happy to hear |
Thanks for your effort, closing! 🥇 |
Hello!
EDIT: See test case in next comment. I also tested with
yamux
and it's the same, which makes me more unsure whether it's a bug or not. If not, please point me in the right direction 👍I noticed that once my server sent it's data and closed the session, i would sometimes get a broken pipe on the client which would cause data loss.
What happens is that the server sends file of ~300kb and immedately closes the stream, returns and closes the session. The client receives the file, but the
s.die
channel in stream.go'sRead
method is called before the internal stream buffer has been emptied.I added some print to the
<-s.die
case and there was still data in the buffer (see code block at the bottom)Is this by design? If so, how should i work around it? I would expect the internal buffer of a stream to be emptied before and not get a "broken pipe" error, but there seems to be some race?
I even verified with wireshark that all bytes are sent over the network and received by the client, but my data is still corrupted sometimes due to this.
The text was updated successfully, but these errors were encountered: