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

Fix race conditions #101

Merged
merged 2 commits into from
Feb 2, 2017
Merged

Conversation

adunham-stripe
Copy link
Contributor

This should fix some various data races, mostly around the isClosing / closeErr fields in the Conn struct. I've taken a similar route as #74, but with full support for older versions of Go that don't support the sync/atomic.Value struct.

@adunham-stripe
Copy link
Contributor Author

This should be ready to go now 😸

@adunham-stripe
Copy link
Contributor Author

@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 {
Copy link
Contributor

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?

Copy link
Contributor

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?

Copy link
Contributor Author

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clever

@liggitt
Copy link
Contributor

liggitt commented Feb 2, 2017

squash the two test commits. just the one question about the .(error) cast, then LGTM

@adunham-stripe
Copy link
Contributor Author

Squashed, and the cast is fixed.

@liggitt liggitt merged commit 3ab6482 into go-ldap:master Feb 2, 2017
@liggitt
Copy link
Contributor

liggitt commented Feb 2, 2017

thanks for the fix

@adunham-stripe
Copy link
Contributor Author

Awesome! Thanks a bunch for merging 😀

@adunham-stripe adunham-stripe deleted the adunham/fix-race branch February 2, 2017 05:44
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