Skip to content

Fix data race in rescuer#120

Merged
brandur merged 1 commit intomasterfrom
brandur-fix-rescuer-race
Dec 17, 2023
Merged

Fix data race in rescuer#120
brandur merged 1 commit intomasterfrom
brandur-fix-rescuer-race

Conversation

@brandur
Copy link
Contributor

@brandur brandur commented Dec 17, 2023

Here, the data race described here in the rescuer. It's a little subtle,
but the basic problem is that defer statements are LIFO, so what can
happen is that the rescuer can be closed while there's still a log
statement deferred on the stack. Because the log statements feed to
t.Logf through a shunt, this can occasionally cause a log line to be
sent to test output after the test has ended, causing the race detector
to detect a race.

The solution is to defer the close operation before the log operation.
All the other maintenance services already had this race condition
patched quite some time ago, but the fix didn't make it to the rescuer,
probably due to an outdated branch or the like.

[1] #116 (comment)

Here, the data race described here in the rescuer. It's a little subtle,
but the basic problem is that `defer` statements are LIFO, so what can
happen is that the rescuer can be closed while there's still a log
statement deferred on the stack. Because the log statements feed to
`t.Logf` through a shunt, this can occasionally cause a log line to be
sent to test output after the test has ended, causing the race detector
to detect a race.

The solution is to `defer` the close operation before the log operation.
All the other maintenance services already had this race condition
patched quite some time ago, but the fix didn't make it to the rescuer,
probably due to an outdated branch or the like.

[1] #116 (comment)
Copy link
Contributor

@bgentry bgentry left a comment

Choose a reason for hiding this comment

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

Brilliant, thanks. Looks like we already did this in all the other maintenance processes but somehow forgot this one.

Is this worth a changelog entry?

@brandur
Copy link
Contributor Author

brandur commented Dec 17, 2023

Thanks!

Is this worth a changelog entry?

TBH, probably not. In real life your logger is never going to disappear before or on the moment you stop your client, so I'm not sure you'd ever realistically run into a problem (even if the service logged a little after the client stopped, it wouldn't be harmful). I'll skip one for now for brevity sake, but lemme know if you disagree.

@brandur brandur merged commit c7b1005 into master Dec 17, 2023
@brandur brandur deleted the brandur-fix-rescuer-race branch December 17, 2023 21:09
@brandur brandur restored the brandur-fix-rescuer-race branch December 21, 2023 21:36
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