Closed yudai closed 4 years ago
Spent several days because of described problem. When do hijack()
conn randomly blocked.
Thank you for PR, hope it will be merged soon.
Figured out some issue with this PR. We also need to return net.Error implementation of ErrTimeout. Or in some cases httputil.NewSingleHostReverseProxy()
will return context closed
error. This commit fixes problem.
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.
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.