receiveLoop() is responsible for receiving the final close message, and transmitLoop() is responsible for replying to it. This creates a race where receiveLoop() might receive the close message and exit before transmitLoop() can reply.
We can fix this by having receiveLoop() pause after receiving a close message. transmitLoop() will reply to it and then return, at which point receiveLoop() will be canceled anyway.
messagePump()
is defined as:receiveLoop()
is responsible for receiving the final close message, andtransmitLoop()
is responsible for replying to it. This creates a race wherereceiveLoop()
might receive the close message and exit beforetransmitLoop()
can reply.We can fix this by having
receiveLoop()
pause after receiving a close message.transmitLoop()
will reply to it and then return, at which pointreceiveLoop()
will be canceled anyway.