Repository navigation
Cancelling queries on timeouts - #3130
Conversation
Are you referring to the fact that for sync, NpgsqlException wraps an IOException wrapping a SocketException (see this test)? If so, I don't think it's a trivial question... There's something more correct about Npgsql simply bubbling up whatever low-level I/O exceptions it encounters - this allows users to unwrap the NpgsqlException and to be left with the standard .NET way of representing the problem. However, I do agree that the inconsistency between sync and async isn't ideal, and that it's a bit cumbersome to work through 3 exception types (and an error code) just to identify a timeout. Can you please open a separate issue for this?
As far as the user-facing cancellation API goes, this is by-design: cancellation is a best-effort thing and there are no guarantees. This is actually one of the few cases where the behavior is explicitly said in the specs:
However, I absolutely agree with what you're saying - for the internal cancellation generated as part of the timeout mechanism, if there's a failure of any sort we can definitely skip the additional waiting time and go directly to breaking the connection. This should be a pretty simple refactoring - I think it should be fine to do as part of this PR (unless you really think otherwise). |
|
(FYI holding off on review until you request one!) |
1e341a8 to
94ead92
Compare
|
@roji not a draft anymore and ready for the review |
roji
left a comment
There was a problem hiding this comment.
Congrats on grokking the codebase and doing this well - it looks pretty close to mergeable... Please see my comments below, there will probably be another round after this, as this isn't trivial functionality.
Thanks again!
|
As we're now never break the connection on timeouts, should I get rid of a |
Makes sense to me... As long as Wait/WaitAsync work like they're supposed to - that's what that parameter was for. |
roji
left a comment
There was a problem hiding this comment.
Thanks, this looks really almost ready to me. I do think we should add a connection string parameter for the 2nd timeout, apart from that there are only a couple of nits left.
…ssage" This reverts commit 9efa8487cd4519dc8ac3305869d47370899a66d5.
2467345 to
23030c4
Compare
Concerning #1567
A few things, which I don't like and IMO deserve a separate pr:
ReadBufferis for a sync query timeout is kind of a pain. I think, it should be done similar to an async query -NpgsqlExceptionwith an inner exception asTimeoutException.NpgsqlConnector.CancelRequestnever throws an exception. Which in case of this pr is a bad thing, as there is no way to be sure if the cancellation was successful or not. I think a connection should be broken immediately if we were unable to cancel a query.@YohDeadfall @roji @Brar thoughts?