-
Notifications
You must be signed in to change notification settings - Fork 822
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
StateChange event no longer fires when connection is observed to be killed #3442
Comments
@vonzshik any chance that this will make it into 5.0.2? |
This is a very tricky issue. While this event does fire on 4.*, it's only so because when the connection is broken we immediately close it. It seems, @roji did change this behavior (most likely because of the multiplexing), but in my opinion it does make more sense unlike the former. |
Not tricky, am fixing it already. |
Well, if you go the way I described, you have to fix every place where we check the connection's state, add at the very least 2 new events (open->broken and broken->closed, maybe even broken->open, or just throw an exception to close the connection before opening). And I might have missed something, so no that simple 😄 |
Also, multiplexing - the connector might break while it's not bound to the connection, so we cannot just call the event from the |
@vonzshik this likely isn't helpful, but the behavior of the SqlServer providers seems to be that the StateChange event only gets called as part of a user interacting with the connection. So it will be called if we try to execute a command and it fails because the connection is now broken, but it doesn't promise to fire the instant that the connection actually breaks. Possibly implementing to this spec would reduce the complexity somewhat? |
And for the |
Yeah, this was indeed the result of the multiplexing work, we even had a test previously checking the event firing, and I removed that check. I admit I don't remember the full reasoning around everything any more. I can't really see a reason not to have this event fire when the connector is broken, and @YohDeadfall's implementation in #3451 looks good to me... I've also double-checked just in case, and SqlClient indeed emits a Closed event if a command is executed on a connection that had been broken before... @vonzshik do you have any specific concerns, do you want to give #3451 a review? |
Steps to reproduce
Here is an NUnit test that reproduces the issue for me. As mentioned in the comments, it passes using 4.1.4 of Npgsql and fails when updated to 5.0.1.1.
The issue
The connection's
StateChange
event should fire whenever the connection state is observed to have changed, such as when running a query against a connection that turns out to have been killed. This worked in the version of Npgsql I was upgrading from and works with MSFT's SqlServer ADO providers.Further technical details
Npgsql version: 4.1.4 -> 5.0.1.1
PostgreSQL version: 12
Operating system: Windows 10
The text was updated successfully, but these errors were encountered: