Repository navigation
Handle timeouts for NpgsqlConnector.DoWaitAsync() - #3142
Conversation
roji
left a comment
There was a problem hiding this comment.
A few thoughts... the WaitAsync is using a timer in order to send the keepalive - this is different from Wait, which simply waits for the timeout to fire and then sends the keepalive; the difference is because up to now we had no async timeouts.
We can now change both methods to use the same technique, and possibly even to merge them together. I think that the sync technique (timing out and then sending the keepalive) is safer since it doesn't involve the concurrency that the timer brings in (in fact, I'm pretty sure there are some race conditions around this with the current code).
Note also how WaitAsync registers performKeepAlive to execute when the user cancellation token is triggered... This is a hacky way to unblock the async read when the user cancels, because again we had no proper cancellation (which we now have). I think we should clean that up as well and simply have the cancellation token trigger cancellation of the read.
Hope all of the above makes sense... and also that you're OK with a wider refactor/cleanup of how waiting works.
Oh, so that's why the
No problems here 😁 |
|
(@vonzshik just to be sure that we work efficiently, when you've made changes and a PR is ready for me to look again, you can request a re-review (the arrows next to my name in the reviewers above) |
Got it! Concerning this PR, while it's mostly done, I have some troubles with cancelling the read by using cancellation token. Right now, we have no way to cancel the async read (there is an issue about remedying this #2437). So, I'm not sure if this PR should be put on hold, merged as is, or maybe use some temporary hack. |
|
Let's put this on hold until #2437 is done, this way we do everything right in one go. |
Is anybody actually working on resolving #2437? I get that in #2437 (comment) @YohDeadfall wrote:
But then again in #2439 (comment) @YohDeadfall wrote:
So I'm kind of unsure whether there is actually some progress on the issue that is blocking this PR and (partially) my replication related work. |
|
BTW: I have an experimental branch where I simply added a |
Am not sure, but I think that issue is orthogonal to @YohDeadfall's new type handlers (which are being punted for 6.0). You can definitely work on this if you want - though maybe @vonzshik is interested in this as he's been looking at cancellation and timeouts recently. Note also that there's an interaction between #2437 and #3130 - it's probably best to wait until the latter is merged. |
Everything is intertwined around async cancellation that's why we need to coordinate our work a lot.
I'm not particularly interested in doing it (enough on my plate already), so @vonzshik if you feel like taking care of this too, please say so and go ahead! |
cf92a8f to
4133df2
Compare
| if (timeout > 0 && async) | ||
| throw new NotSupportedException("WaitAsync with timeout isn't supported when used on .NET Framework. Please consider moving to .NET Core."); | ||
|
|
||
| if (timeout <= 0 && cancellationToken.CanBeCanceled) |
There was a problem hiding this comment.
Shouldn't we always through for CanBeCanceled, regardless of timeout?
There was a problem hiding this comment.
There is a case with a KeepAlive. While the CancellationToken doesn't cancel write or read from a socket, we do still have some checks for cancellationToken.ThrowIfCancellationRequested().
There was a problem hiding this comment.
Hmm, OK... It's not very important, but these checks don't seem to be enough to say that WaitAsync actually supports the cancellation tokens - the really interesting case is to actually cancel a read operation, which we can't do on this TFM. So I'm leaning towards throwing immediately for any non-None cancellation token.
But I'm fine to merge either way - let me know which way you want to do it.
There was a problem hiding this comment.
Oh, I see you actually already did this. Merging.
There was a problem hiding this comment.
Well, not really - it's still working the same. We check for the timeout, and if it is less or equal to zero, then we check for the cancellation token. I don't mind if you do change it.
|
Thanks for the promotion! |
|
That's very cool. Thank you, @YohDeadfall. |
|
Just did a tweet :) Thanks for suggesting this @YohDeadfall! |
|
You even could tweet yourself using hashtag |
|
(@warcha just waiting for your Twitter handle too!) |
|
Sent a guess with 99.(9)% probably privately. |
|
Will wait for @warcha to confirm they want to be publicly mentioned etc. |
|
Thanks guys for your generous offer, unfortuntately I'm not on twitter so I'm all good here. Thanks again. |
Closes #3140