-
Notifications
You must be signed in to change notification settings - Fork 363
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 race conditions #101
Fix race conditions #101
Conversation
This should be ready to go now 😸 |
@liggitt - Anything I can do to help move this forward? |
conn.go
Outdated
@@ -333,8 +344,8 @@ func (l *Conn) processMessages() { | |||
for messageID, msgCtx := range l.messageContexts { | |||
// If we are closing due to an error, inform anyone who | |||
// is waiting about the error. | |||
if l.isClosing && l.closeErr != nil { | |||
msgCtx.sendResponse(&PacketResponse{Error: l.closeErr}) | |||
if l.isClosing() && l.closeErr.Load().(error) != nil { |
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.
what does l.closeErr.Load().(error)
do if no error was stored in closeErr?
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.
pretty sure it'll panic... do an uncast nil check here and cast inside the block?
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.
Yeah, good catch here - this was supposed to be an uncast check. Fixed!
|
||
// setClosing sets the closing value to true | ||
func (l *Conn) setClosing() { | ||
atomic.AddUint32(&l.closeCount, 1) |
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.
clever
squash the two test commits. just the one question about the |
e1f6684
to
668db80
Compare
Squashed, and the cast is fixed. |
thanks for the fix |
Awesome! Thanks a bunch for merging 😀 |
This should fix some various data races, mostly around the
isClosing
/closeErr
fields in theConn
struct. I've taken a similar route as #74, but with full support for older versions of Go that don't support thesync/atomic.Value
struct.