Repository navigation
Fully honor timeouts during connection phase - #3229
Conversation
|
Two additional notes - this isn't yet ready for merging.
|
There was a problem hiding this comment.
UserTimeout only holds current timeout. Buffer's timeout is set during connector's ReadMessage.
Also, the connector sets the timeout only for the ReadBuffer.
There was a problem hiding this comment.
UserTimeout only holds current timeout. Buffer's timeout is set during connector's ReadMessage.
Right, but the first time that a message will be read (i.e. for authentication) the timeout will be properly set on the read buffer - just like the regular flow when executing a command (that's why the test passes). In fact, if we don't set UserTimeout, the test fails because ReadMessage sets the buffer's timeout from it (and it means "no timeout").
Also, the connector sets the timeout only for the ReadBuffer.
That's true, I'll set the write timeout here as well. The design is currently smelly, in that the read timeout is set automatically from NpgsqlConnector.UserTimeout (in ReadMessage), but the write timeout is set via a completely different mechanism. This is mainly because reading always goes through one place (ReadMessage), but writing can happen via various different places.
Even though it's a code smell, I propose to leave it as it is as it doesn't have an actual impact - we can always clean up later if we want.
There was a problem hiding this comment.
Right, but the first time that a message will be read (i.e. for authentication) the timeout will be properly set on the read buffer - just like the regular flow when executing a command (that's why the test passes).
But it wouldn't be set for reading a response for the ssl request just below.
Even though it's a code smell, I propose to leave it as it is as it doesn't have an actual impact - we can always clean up later if we want.
It's definitely something we should take another look. But I agree, that it can (and should) be done later.
There was a problem hiding this comment.
But it wouldn't be set for reading a response for the ssl request just below.
Good catch. I've updated to apply the timeout both directly to the read buffer, and also to UserTimeout.
vonzshik
left a comment
There was a problem hiding this comment.
Looks great! A few small changes, and it should be ok to merge.
Improve PG mocking infrastructure to support connection-time scenarios. Fixes npgsql#3227
2a14489 to
bfdacc8
Compare
|
Tested on my system and the sync Open works as expected: 10/13/20 09:44:15.643 [10] [Debug] Npgsql.LogDebug: Authenticating... Hooray! One thing: the OpenAsync does not. Is there a different way to apply a timeout for async? I know the socker ReceiveTimeout is not applicable for this. May something similar to my hack in #3227 (but no need for reflection)? |
|
@russellfoster this PR was definitely supposed to address async timeouts as well. Which version of .NET Core are you using? Cancellation tokens (which are used for timeouts) are only honored in recent versions. |
That is, .net 5 for the |
|
OK, dependant on Net version. I'm on 4.6.1. Yes old, I know :) |
|
@russellfoster yeah, that would be the reason. Definitely consider moving to .NET Core! |
Improve PG mocking infrastructure to support connection-time scenarios.
@russellfoster while working on the PostgreSQL mocking infrastructure for testing the issue, I ended up doing the fix as well.
Fixes #3227
Replaces #3226
/cc @russellfoster @vonzshik