-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Deadlock when calling BufferedWriteSyncer.Stop
#1428
Comments
prashantv
added a commit
that referenced
this issue
Apr 12, 2024
Fixes #1428. Stop signals the flush loop to end, but if the flush ticker has fired after we took the lock, then it tries to `Sync`, and waits for the same lock that `Stop` is holding. This causes a deadlock, as `Stop` holds the lock waiting for flush to end. Fix by waiting for the flush loop to end outside of the critical section. We only need to wait (and call Sync) if the write syncer has been initialized and stopped.
Thank you for the detailed bug report, you're exactly right with your analysis, |
prashantv
added a commit
that referenced
this issue
Apr 13, 2024
Fixes #1428. Stop signals the flush loop to end, but if the flush ticker has fired after we took the lock, then it tries to `Sync`, and waits for the same lock that `Stop` is holding. This causes a deadlock, as `Stop` holds the lock waiting for flush to end. Fix by waiting for the flush loop to end outside of the critical section. We only need to wait (and call Sync) if the write syncer has been initialized and stopped.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Describe the bug
Upon calling
Stop
there's a small chance of deadlock. Happens sometimes on gov1.21.3
zapv1.22.0
.To Reproduce
Can't really figure out how to reproduce it without touching said code yet.
This is what I suspect is happening:
When
Stop
is called, it spawns a goroutine that locks mutex,zap/zapcore/buffered_write_syncer.go
Lines 195 to 196 in b15585b
stops timer and tells
flushLoop
to breakzap/zapcore/buffered_write_syncer.go
Lines 208 to 210 in b15585b
However if timer fired before stop occurred here
zap/zapcore/buffered_write_syncer.go
Lines 176 to 184 in b15585b
It calls
Sync
that tries to acuire locked mutexzap/zapcore/buffered_write_syncer.go
Lines 159 to 160 in b15585b
So
Stop
goroutine holds mutex and waits forflushLoop
to close channel on defer whileflushLoop
waits onSync
to finish, but it can't since mutex is locked inStop
goroutineThe text was updated successfully, but these errors were encountered: