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

materialize: don't use locks in the extended logger #2043

Merged
merged 1 commit into from
Oct 11, 2024

Conversation

williamhbaker
Copy link
Member

@williamhbaker williamhbaker commented Oct 11, 2024

Description:

The use of a mutex in both the extended logger event handler and the async logger functions was simple, but there was a potential deadlock if the event handler needed to stop the logger and wait for it to stop while holding the lock, and the logger timer ticked over at nearly the same instant making the logger need to get the lock also to finish its last log before exiting.

This updates the extended logger to not use locks at all, since it wasn't far from being able to do that in the first place. The "count" values that are read concurrently by the async loggers have been changed to use atomics, and for good measure the "round" counter is provided as an explicit argument to them, even though it doesn't strictly need to be, it's just easier to understand this way.

Workflow steps:

(How does one use this feature, and how has it changed)

Documentation links affected:

(list any documentation links that you created, or existing ones that you've identified as needing updates, along with a brief description)

Notes for reviewers:

(anything that might help someone review this PR)


This change is Reviewable

@williamhbaker williamhbaker added the change:unplanned Unplanned change, useful for things like doc updates label Oct 11, 2024
@williamhbaker williamhbaker requested a review from a team October 11, 2024 20:39
Copy link
Member

@mdibaiee mdibaiee left a comment

Choose a reason for hiding this comment

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

LGTM % small nit

asyncLog()
l.mu.Unlock()
}, loggingFrequency)
return repeatAsync(func() { asyncLog() }, loggingFrequency)
Copy link
Member

Choose a reason for hiding this comment

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

Can be simplified to:
repeatAsync(asyncLog, loggingFrequency)

The use of a mutex in both the extended logger event handler and the async
logger functions was simple, but there was a potential deadlock if the event
handler needed to stop the logger and wait for it to stop while holding the
lock, and the logger timer ticked over at nearly the same instant making the
logger need to get the lock also to finish its last log before exiting.

This updates the extended logger to not use locks at all, since it wasn't far
from being able to do that in the first place. The "count" values that are read
concurrently by the async loggers have been changed to use atomics, and for good
measure the "round" counter is provided as an explicit argument to them, even
though it doesn't strictly need to be, it's just easier to understand this way.
@williamhbaker williamhbaker merged commit 6724620 into main Oct 11, 2024
53 checks passed
@williamhbaker williamhbaker deleted the wb/logging-deadlock branch October 11, 2024 20:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
change:unplanned Unplanned change, useful for things like doc updates
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants