-
Notifications
You must be signed in to change notification settings - Fork 438
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 data race of Token result Pool #149
Conversation
core/flow/slot.go
Outdated
if r.Status() == base.ResultStatusBlocked { | ||
return r | ||
result.DeepCopyFrom(r) |
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.
Why a copy is needed here?
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.
It's not needed, maybe return r is enough
core/system/slot.go
Outdated
for _, rule := range rules { | ||
passed, m := s.doCheckRule(rule) | ||
if passed { | ||
continue | ||
} | ||
return base.NewTokenResultBlockedWithCause(base.BlockTypeSystemFlow, base.BlockTypeSystemFlow.String(), rule, m) | ||
result.ResetToBlockedWithCauseFrom(base.BlockTypeSystemFlow, base.BlockTypeSystemFlow.String(), rule, m) |
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.
Check result nil here? (in case previous customized slots cleared the result)
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.
make sense
Codecov Report
@@ Coverage Diff @@
## master #149 +/- ##
==========================================
- Coverage 43.48% 42.72% -0.77%
==========================================
Files 67 67
Lines 2863 2926 +63
==========================================
+ Hits 1245 1250 +5
- Misses 1479 1537 +58
Partials 139 139
Continue to review full report at Codecov.
|
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.
LGTM
Thanks! |
Describe what this PR does / why we need it
Root cause is here:
Refer to: https://github.com/alibaba/sentinel-golang/commit/975debd7075d071473fcbcd17c3dbc3bd201a2da#diff-604f4192deea5adf9c159e5f88f64630R93
r is the same Pointer with context.Output.LastResult. Sentinel refurbish the r. But When user call Exit() by manually, will call context.Output.LastResult(the refurbished TokenResult might be got by other goroutine), it causes DATA RACE.
Does this pull request fix one issue?
Describe how you did it
Describe how to verify it
Special notes for reviews