-
Notifications
You must be signed in to change notification settings - Fork 71
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
fix issue120 and issue103: add mutex to prevent data race in websocket write message and use named return values for WritePkg method #121
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we use the packetLock in the session?
@No-SilverBullet good job. Maybe u can also check the tcp write is thread safe or not. refer issue #103 |
Based on this issue120 and document( https://pkg.go.dev/github.com/gorilla/websocket#hdr-Concurrency ), the writeMessage function in gorrila package is not concurrency safe, so a lock is added to prevent race conditions. |
ok |
…ptured panic to caller
refactor:use named return values for WritePkg method to return the ca…
Based on this issue120 and document( https://pkg.go.dev/github.com/gorilla/websocket#hdr-Concurrency ), the writeMessage function in gorrila package is not concurrency safe, so a lock is added to prevent race conditions. |
refactor: error format in WritePkg method
What this PR does:
based on doc: https://pkg.go.dev/github.com/gorilla/websocket#hdr-Concurrency and #120
1.add lock (sync.Mutex) in gettyWSConn struct
2. add new function 'threadSafeWriteMessage' to ensure that only one thread can send a message at a time,preventing race conditions.
based on #103
3. use named return values for WritePkg method to return the captured panic to caller, which can prevent the panic in caller.
Which issue(s) this PR fixes:
Fixes #120, #103
Special notes for your reviewer:
Does this PR introduce a user-facing change?: