This repository has been archived by the owner on Apr 26, 2024. It is now read-only.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add cancellation support to
ReadWriteLock
#12120Add cancellation support to
ReadWriteLock
#12120Changes from 1 commit
89fe787
f1f363d
9744823
3241adc
68f5abe
28dbe41
c9f85e4
716cded
c4a2a58
31a2bb2
1c1b46a
65f97fa
cadfe0a
1cd035b
4c47827
1b9ec9b
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
could we, instead of all this, do:
... possibly with more
stop_cancellation
? Or does that not work?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.
release()
must only be called after the yield, so I'm guessing you meant:which I was originally hesitant to do because of re-entrancy in the happy path:
to_wait_on_defer.callback(...)
.yield
/ body of the context manager, we may or may not do a blocking await. If we block, then theto_wait_on_defer.callback()
call gets exited, otherwise we remain within theto_wait_on_defer.callback()
call.If we're no longer inside the
callback()
call,release()
will be called instantly with the current logging context.Otherwise if we're still inside the
callback()
call,release()
won't be called until we next block or terminate and will have the sentinel context.The sometimes-extra delay before
release()
is tricky to reason about, but I think the proposed code would be alright.As an alternative, I'm very tempted by @erikjohnston's suggestion of delaying CancelledErrors:
Where
delay_cancellation
would hold on to the CancelledError and only raise it onceto_wait_on_defer
resolves.We'd get better maintainability at the cost of having the crud associated with cancelled requests lingering a little while longer, but maybe that's a worthwhile tradeoff.
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.
oh, duh. Yes, of course.
ugh, right, yes, let's avoid that.
And yes,
delay_cancellation
looks like it might be worth exploring.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.
I had a go at using a delay in cadfe0a.
We now depend on #12180 for
delay_cancellation
of course.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.
presumably we need to do this even if
to_wait_on_defer
ends up erroring, so this needs to beThere 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.
I'll make the change for the sake of robustness, but all of the Deferreds that represent lock release, and thus also
to_wait_on_defer
, should never error.