hashicorp/yamux

Data lost when closing Session

yipal opened this issue · 2 comments

yipal commented

Hi all, I ran into an issue, and I wanted to get your opinion on what the correct behavior should be.

I have a yamux client that writes data to a Stream, and then closes the Stream, and also the Session.
The problem is that some times, all the data arrives at the other end, and other times, some data remains in the send queue when the underlying connection actually closes.

First, this causes this warning message:
[ERR] yamux: Failed to write header: tls: use of closed connection

Second, the data does not arrive at the other end.

This commit contains a unit test that shows what happens; the failure happens only sometimes because it is a race condition: yipal@a5eed1e

I noticed that the existing code finishes sending the data when the client calls Stream.Close(), so that makes me think
the correct behavior is for Session.Close() to also finish draining the send queue before actually closing the underlying connection.

r0l1 commented

I tested it with our yamux fork and I can't reproduce the error. Could you please recheck?
https://github.com/desertbit/yamux

Edit: we made some changes to the closing functionality of yamux to be compatible for our orbit rpc project. Would be good to know, if this bug effects also our fork.

The test in yipal@a5eed1e currently passes fine, so I'm assuming the bug is gone.