Skip to content
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

Remove mutex from sessionWS #1141

Conversation

joshgarnett
Copy link
Contributor

There are six different calls to s.Lock() in sessionWS. Three of these locks are around calls to SetWriteDeadline and WriteMessage on the WebSocket. WriteMessage will block for up to the timeout set in SetWriteDeadline, which has a default of 5000 milliseconds. This lock is also acquired by SendBytes to determine if the session has been stopped. This is a problem as the event processing methods in StatusRegistry and Track call SendBytes directly on the Session. If one of the Sessions being written to has delays in writing data, this could cause backups in the event processing.

This change is more complex than #1140. It fully removes the mutex from sessionWS. All writes have been moved to only occur within processOutgoing so no panics are generated by concurrent writes. The stopped variable is converted to an atomic.Bool, which is only used in the Close method to prevent more than one Close call being made. As the outgoingCh is not closed, Send() is used to send the final messages and then the ctxCancelFn is called, which causes a Close message to be sent in processOutgoing after all messages are sent. The ping backoff logic was also simplified.

There are six different calls to s.Lock() in sessionWS.  Three of these locks are around calls to SetWriteDeadline and WriteMessage on the WebSocket.  WriteMessage will block for up to the timeout set in SetWriteDeadline, which has a default of 5000 milliseconds.  This lock is also acquired by SendBytes to determine if the session has been stopped.  This is a problem as the event processing methods in StatusRegistry and Track call SendBytes directly on the Session.  If one of the Sessions being written to has delays in writing data, this could cause backups in the event processing.

This change is more complex than heroiclabs#1140.  It fully removes the mutex from sessionWS.  All writes have been moved to only occur within processOutgoing so no panics are generated by concurrent writes.  The stopped variable is converted to an atomic.Bool, which is only used in the Close method to prevent more than one Close call being made.  As the outgoingCh is not closed, Send() is used to send the final messages and then the ctxCancelFn is called, which causes a Close message to be sent in processOutgoing after all messages are sent.  The ping backoff logic was also simplified.
@CLAassistant
Copy link

CLAassistant commented Nov 14, 2023

CLA assistant check
All committers have signed the CLA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants