-
Notifications
You must be signed in to change notification settings - Fork 231
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
Aboard Read()/Write() by SetDeadline() with past time #51
Conversation
Spent several days because of described problem. When do |
Figured out some issue with this PR. We also need to return net.Error implementation of ErrTimeout. Or in some cases |
* flow control was assuming a `Read` consumed the entire buffer * flow control fix reduces memory utilization when receiving large streams of data * use timer pool to reduce allocations * use static handler function pointer to avoid closure allocations for every frame
Thank you for your submission! We require that all contributors sign our Contributor License Agreement ("CLA") before we can accept the contribution. Read and sign the agreement Learn more about why HashiCorp requires a CLA and what the CLA includes 1 out of 3 committers have signed the CLA.
Have you signed the CLA already but the status is still pending? Recheck it. |
Closed by #82 |
Hello, thanks for the handy library.
Problem Observed
When an HTTP server is served on a
yamux.Session
,Hijack()
onhttp.ResponseWriter
blocks forever, which means protocols that depend on hijacking (protocol upgrade) such as Websocket does not work with yamux.Problem Detail
In
net/http
,Set(Read/Write)Deadline()
withnet.aLongTimeAgo
is used to abort pendingRead()/Write()
by setting the unix epoch + 1 second.Hijack()
uses this method (and I think there are some more cases) to abortRead()
as well.In the document of
net.Conn
,SetDeadline()
is described as below:Setting a past time is supposed to cancel any pending
Read()/Write()
on the connection.However, the current implementation of
yamux.Stream
doesn't support this type of cancelation. Libraries expect this behavior therefore can block forever unexpectedly with yamux.Suggested Resolution
When
SetDeadline()
is called, retryRead()
orWrite()
by using the notification channels.I think there would be no side effects caused by this change, since when you would not provide a past time to
SetDeadline()
when you actually don't expect cancelation by that.