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: deadlock when replacing logging stream sink #227

Merged
merged 4 commits into from
Dec 5, 2024

Conversation

boxdot
Copy link
Collaborator

@boxdot boxdot commented Dec 5, 2024

When setting a new stream sink in SendToDartLogger, we lock the global
rw lock for writing. However, if the lock already contained a sink, it
was droppen at the same line when replacing it. A stream sink logs a
message on drop, and therefore SendToDartLogger tries to lock the
global rw lock again, this time for reading. The lock is not reentrant,
so it deadlocks.

This makes sure we drop the previous sink after unlocking the rw lock.

In particular, this fixes hot restart in Flutter.

Fixes #225

When setting a new stream sink in `SendToDartLogger`, we lock the global
rw lock for writing. However, if the lock already contained a sink, it
was droppen at the same line when replacing it. A stream sink logs a
message on drop, and therefore `SendToDartLogger` tries to lock the
global rw lock again, this time for reading. The lock is not reentrant,
so it deadlocks.

This makes sure we drop the previous sink *after* unlocking the rw lock.

Fixes #225
@boxdot boxdot changed the title fix: deadlock when replacing stream sink in SendToDartLogger fix: deadlock when replacing logging stream sink Dec 5, 2024
Copy link
Contributor

@raphaelrobert raphaelrobert left a comment

Choose a reason for hiding this comment

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

Thanks, just one nit.

@boxdot boxdot requested a review from raphaelrobert December 5, 2024 12:00
Copy link
Contributor

@raphaelrobert raphaelrobert left a comment

Choose a reason for hiding this comment

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

Thanks!

@boxdot boxdot merged commit 0c27503 into main Dec 5, 2024
8 checks passed
@boxdot boxdot deleted the dima/dart-log-deadlock branch December 5, 2024 13:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Flutter hot restart hangs
2 participants