-
Notifications
You must be signed in to change notification settings - Fork 522
Be careful with logcontext in DeferredEvent
#19142
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
Changes from 1 commit
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 |
|---|---|---|
|
|
@@ -1029,7 +1029,8 @@ def __init__(self, clock: Clock) -> None: | |
|
|
||
| def set(self) -> None: | ||
| if not self._deferred.called: | ||
| self._deferred.callback(None) | ||
| with PreserveLoggingContext(): | ||
| self._deferred.callback(None) | ||
|
Contributor
Author
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. This usage is actually probably fine given you can't get a handle to the raw deferred and add some callbacks to the chain that could cause the logcontext to change.
Contributor
Author
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. This was actually a problem, see #19146 (comment) for an explanation |
||
|
|
||
| def clear(self) -> None: | ||
| if self._deferred.called: | ||
|
|
||
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.
This is the main fix!
See the Deferred callbacks section of our logcontext docs for more info (specifically using solution 2).
Heads-up, I wrote the docs too so it's my assumptions/understanding all the way down. Apply your own scrutiny.