-
Notifications
You must be signed in to change notification settings - Fork 405
Fix lost logcontext when using timeout_deferred(...)
#19090
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
base: develop
Are you sure you want to change the base?
Changes from all commits
5eea20a
6be53d8
9478194
33776c0
4b9441e
630792c
73080af
5179ea3
202906e
0325f97
18ae299
a31eadd
71d490c
8328e1f
140bb59
9aa4919
7bb2ffc
4e576b7
a782d04
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 |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Fix lost logcontext warnings from timeouts in sync and requests made by Synapse itself. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -896,7 +896,7 @@ def run_in_background( | |
| # If the function messes with logcontexts, we can assume it follows the Synapse | ||
| # logcontext rules (Rules for functions returning awaitables: "If the awaitable | ||
| # is already complete, the function returns with the same logcontext it started | ||
| # with."). If it function doesn't touch logcontexts at all, we can also assume | ||
| # with."). If the function doesn't touch logcontexts at all, we can also assume | ||
| # the logcontext is unchanged. | ||
| # | ||
| # Either way, the function should have maintained the calling logcontext, so we | ||
|
|
@@ -905,11 +905,21 @@ def run_in_background( | |
| # to reset the logcontext to the sentinel logcontext as that would run | ||
| # immediately (remember our goal is to maintain the calling logcontext when we | ||
| # return). | ||
| logcontext_debug_logger.debug( | ||
| "run_in_background(%s): deferred already completed and the function should have maintained the logcontext %s", | ||
| instance_id, | ||
| calling_context, | ||
| ) | ||
| if current_context() != calling_context: | ||
| logcontext_error( | ||
| "run_in_background(%s): deferred already completed but the function did not maintain the calling logcontext %s (found %s)" | ||
| % ( | ||
| instance_id, | ||
| calling_context, | ||
| current_context(), | ||
| ) | ||
| ) | ||
| else: | ||
| logcontext_debug_logger.debug( | ||
| "run_in_background(%s): deferred already completed and the function should have maintained the calling logcontext %s", | ||
|
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 find this log line confusing to read, especially as the alternative is "the function did not maintain the calling logcontext". Does that mean that if we got here, the function did maintain the calling logcontext? And if so, should the log line just be: |
||
| instance_id, | ||
| calling_context, | ||
| ) | ||
| return d | ||
|
|
||
| # Since the function we called may follow the Synapse logcontext rules (Rules for | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -808,7 +808,8 @@ def time_it_out() -> None: | |
| timed_out[0] = True | ||
|
|
||
| try: | ||
| deferred.cancel() | ||
| with PreserveLoggingContext(): | ||
| deferred.cancel() | ||
|
Comment on lines
+811
to
+812
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 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.
Comment on lines
+811
to
+812
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. In an ideal world, I think it should be possible to call the deferred callback/errbacks/cancel with some logcontext. I spent too much time trying to figure out the intricacies here and trying to use solution 3 from the Deferred callbacks docs but wasn't successful. It makes me question if what I wrote there is correct in the first place 🤔 The problem is that calling I can't tell if the problem is a) our function just isn't following logcontext rules (and how to resolve that well) or b) we should Instead of banging my head against this more, I've opted to go for the simple route 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 think I somewhat understand the problem, but don't really understand it enough to give you an answer here. If you ever want to jump on a call to try and talk this through (or even rubber-duck it with me) shout and I'd be happy to :) |
||
| except Exception: # if we throw any exception it'll break time outs | ||
| logger.exception("Canceller failed during timeout") | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.