Skip to content

fix: rueidislock deadlock caused by the absence of peers#458

Merged
rueian merged 2 commits intomainfrom
fix-rueidislock-457
Jan 27, 2024
Merged

fix: rueidislock deadlock caused by the absence of peers#458
rueian merged 2 commits intomainfrom
fix-rueidislock-457

Conversation

@rueian
Copy link
Copy Markdown
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
Copy Markdown

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
Comment thread rueidislock/lock.go
m.mu.RLock()
for _, g := range m.gates {
select {
case g.ch <- struct{}{}:
Copy link
Copy Markdown
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.

Comment thread rueidislock/lock.go
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
Copy Markdown
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.

Comment thread rueidislock/lock.go
g.ch <- struct{}{}
} else if m.gates != nil {
select {
case g.ch <- struct{}{}:
Copy link
Copy Markdown
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