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: rueidislock deadlock caused by the absence of peers #458

Merged
merged 2 commits into from
Jan 27, 2024

Conversation

rueian
Copy link
Collaborator

@rueian rueian commented Jan 26, 2024

fixes #457

There is a rare chance that when receiving bulking invalidation and all peers are aborted, the following line

g.ch <- struct{}{}
blocks indefinitely and causes deadlock reported in the #457.

This PR removes the unnecessary notification to the g.ch from the bulking invalidation and makes the mutex never be blocked.

@codecov-commenter
Copy link

codecov-commenter commented Jan 26, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (33e9233) 95.98% compared to head (627192e) 95.99%.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #458   +/-   ##
=======================================
  Coverage   95.98%   95.99%           
=======================================
  Files          67       67           
  Lines       31543    31528   -15     
=======================================
- Hits        30276    30264   -12     
+ Misses       1085     1083    -2     
+ Partials      182      181    -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@rueian rueian force-pushed the fix-rueidislock-457 branch from 12ac70a to dd517c1 Compare January 27, 2024 09:29
@rueian rueian force-pushed the fix-rueidislock-457 branch from dd517c1 to 627192e Compare January 27, 2024 11:05
@@ -234,10 +232,6 @@ func (m *locker) onInvalidations(messages []rueidis.RedisMessage) {
if messages == nil {
m.mu.RLock()
for _, g := range m.gates {
select {
case g.ch <- struct{}{}:
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This may cause the below g.ch <- struct{}{} below stuck.

for i := int32(0); i < m.totalcnt; i++ {
cases = append(cases, reflect.SelectCase{Dir: reflect.SelectRecv, Chan: reflect.ValueOf(g.csc[i])})
}
reflect.Select(cases)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is no longer needed because we already clear each of theg.csc channel before entering the monitoring function.

g.ch <- struct{}{}
} else if m.gates != nil {
select {
case g.ch <- struct{}{}:
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Notify one peer if any without blocking.

@rueian rueian added the bug Something isn't working label Jan 27, 2024
@rueian rueian merged commit 1c5919c into main Jan 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

occurs deadlock when using rueidislock
2 participants