Repository navigation
Conversation
|
@roji It would be great if you could take a look at this pull request |
|
|
||
| bool IsHostDown(Exception reason) | ||
| => reason is NpgsqlException { IsTransient: true } ne && | ||
| (ne.InnerException is not TimeoutException || Settings.CancellationTimeout != -1) || |
There was a problem hiding this comment.
I'm pretty sure this whole logic is for the case when we hit an error during a query.
As for when hit an error during physical open, I 'think' there's no point in trying to differentiate between exceptions. Every single physical open is the exact same (unlike queries), so there's no reason to assume that the next physical open will succeed unlike the previous one. Which is why I propose to just always mark it as offline if we fail.
@roji I'll need your opinion here.
There was a problem hiding this comment.
Partly agree. You're right that the CancellationTimeout check is query-specific: during a physical open there's no command that could have timed out, so a timeout always means the host isn't responding, and I've made that unconditional for open.
I wouldn't go as far as marking the host offline on any open failure though. Not every open failure says anything about the host: authentication errors (28xxx), 3D000 for a missing database, "No username could be found", SSL/GSS negotiation failures. If we mark the host offline for those, a perfectly healthy host gets skipped for Host Recheck Seconds; if every host "fails" like that, the user ends up with "No suitable host was found." instead of the real error, and DataSource.Clear() drops the pool on every bad-password attempt. Unknown_state_on_connection_authentication_failure already asserts that the state stays Unknown in that case, so I kept the IsHostDown filtering and only relaxed it for timeouts during open via duringOpen.
@roji would still be good to hear your take.
| // A nested break (e.g. a timeout while reading the startup response) skips | ||
| // marking the host offline because we're still connecting. If the outer Open | ||
| // ultimately failed, we still want the host to be marked offline. | ||
| if (markHostAsOfflineOnConnecting) |
There was a problem hiding this comment.
Since we're using markHostAsOfflineOnConnecting in a single place, what if we just get rid of it and move MarkHostAsOffline to NpgsqlConnector.Open? Something like:
try
{
await OpenCore(...);
}
catch (Exception ex)
{
MarkHostAsOffline(ex);
throw;
}There was a problem hiding this comment.
Done, thanks. Dropped the parameter and moved the marking into NpgsqlConnector.Open. Break no longer has any open-specific logic
17a6971 to
6e0882f
Compare
A host that accepts TCP but never answers the startup handshake stayed in the Unknown state. The read timeout breaks the connector while it is still Connecting, which intentionally skips marking the host offline, and the following Break from Open returns early because the connector is already Broken. Mark the host offline when the final Open attempt fails too, so subsequent connections skip it until Host Recheck Seconds expires, like a host that refuses connections. Fixes npgsql#6733
Remove the markHostAsOfflineOnConnecting parameter from Break and instead mark the host offline from NpgsqlConnector.Open, once the physical open has definitively failed. Also don't apply the query-only CancellationTimeout check when a physical open fails: a timed-out open always means the host is unresponsive. Other non-host failures during open (e.g. authentication errors) still leave the host state untouched. Simplify the test to use PgPostmasterMock instead of a hand-rolled TcpListener.
6e0882f to
12cd2f7
Compare
A host that accepts TCP but never answers the startup handshake stayed in the Unknown state. The read timeout breaks the connector while it is still Connecting, which intentionally skips marking the host offline, and the following Break from Open returns early because the connector is already Broken.
Mark the host offline when the final Open attempt fails too, so subsequent connections skip it until Host Recheck Seconds expires, like a host that refuses connections.
with fix, we can see this in output from issue for both cases (tested on real multihost pg)
Fixes #6733