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.
This commit fixes an edge case where the
body
passed towaitForSendErr
can be written to after returning from the function. This happens whensendReady
is buffered on thesendCh
and the session is shutdown or the write times out.When this condition happens and
waitForSendErr
has not yet exited, thebody
is safely copied into a temporary buffer insend
. OtherwisewaitForSendErr
safely created a copy of thebody
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