-
Notifications
You must be signed in to change notification settings - Fork 630
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
CASSGO-41 Fix deadlock in refresh debouncer stop #1767
base: trunk
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -274,6 +274,32 @@ func TestRefreshDebouncer_EventsAfterRefreshNow(t *testing.T) { | |
} | ||
} | ||
|
||
// https://github.com/gocql/gocql/issues/1752 | ||
func TestRefreshDebouncer_DeadlockOnStop(t *testing.T) { | ||
// there's no way to guarantee this bug manifests because it depends on which `case` is picked from the `select` | ||
// with 4 iterations of this test the deadlock would be hit pretty consistently | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this comment indicate that you were reliably reproducing it without the fix in place or is it just speculating that 4 should be enough to hit it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was reliably reproducing it with 4 without the fix in place |
||
const iterations = 4 | ||
for i := 0; i < iterations; i++ { | ||
refreshCalledCh := make(chan int, 5) | ||
refreshDuration := 500 * time.Millisecond | ||
fn := func() error { | ||
refreshCalledCh <- 0 | ||
time.Sleep(refreshDuration) | ||
return nil | ||
} | ||
d := newRefreshDebouncer(50*time.Millisecond, fn) | ||
timeBeforeRefresh := time.Now() | ||
_ = d.refreshNow() | ||
<-refreshCalledCh | ||
d.debounce() | ||
d.stop() | ||
timeAfterRefresh := time.Now() | ||
if timeAfterRefresh.Sub(timeBeforeRefresh) < refreshDuration { | ||
t.Errorf("refresh debouncer stop() didn't wait until flusher stopped") | ||
} | ||
} | ||
} | ||
|
||
func TestErrorBroadcaster_MultipleListeners(t *testing.T) { | ||
b := newErrorBroadcaster() | ||
defer b.stop() | ||
|
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.
I would say this is a bit of an abuse of contexts. Instead I would keep the old behavior but just change a small thing. Add another
chan struct{}
here calleddone
that isdefer close(done)
influsher
. Then instop()
keep what was there but don't write toquit
(I'm not really sure what the purpose of that was anyways) and just close it. Then do<-done
to wait forflusher
to stop.