hashicorp / yamux

Golang connection multiplexing library
Mozilla Public License 2.0
2.19k stars 232 forks source link

Protect reads of `sendReady.Body` with mutex and temp buffer #102

Closed mafredri closed 2 years ago

mafredri commented 2 years ago

This commit fixes an edge case where the body passed to waitForSendErr can be written to after returning from the function. This happens when sendReady is buffered on the sendCh and the session is shutdown or the write times out.

When this condition happens and waitForSendErr has not yet exited, the body is safely copied into a temporary buffer in send. Otherwise waitForSendErr safely created a copy of the body and exits, this essentially results in double buffering for the edge case which seems acceptable.

Related to: #40 Detailed analysis: https://github.com/coder/coder/issues/2429

jefferai commented 2 years ago

Thank you!