-
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
Fix backend protocol version fallback bug #83
Conversation
NpgsqlNetworkStream.Dispose() no longer tries to close its Connector unless the Connector has been explicitly attached to it. Save the NpgsqlNetworkStream on Connector so it can be attached after successful startup. Cleaned up CloseState.Open().
I think this dispose bug is floating around for a long time. We didn't get it before because it would only happen on protocol 2 only servers. Nice catch! Some observations:
One random comment: I think we could refactor NpgsqlNetworkStream to extend BufferedStream instead of NetworkStream (and maybe even change its name to just NpgsqlStream as it wouldn't be a networkstream anymore :) ) and use it as the NpgsqlConnector.Stream property, this way we would have a much better control about how to interact with the stream. But now I think we could use it to be a little smarter and encapsulate some of those stream logic and save us a lot of stream variables :) What do you think? |
On Mon, Oct 28, 2013 at 1:34 PM, Francisco Figueiredo Jr. <
As we've discussed elsewhere, Npgsql should keep its own thread dedicated So I think it's best to leave this alone as a known less-then-optimal -Glen
|
It would be awesome if VS had a mind reading capability... :) In fact, the problem NpgsqlNetworkStream solves isn't related to the connection being dropped. It was more related to the fact that when the client application exits and then terminate its process, Npgsql couldn't know, by itself, that it should close all the connections by sending the Terminate message to backend. There is a problem though on Mono 3.x where this message still appears which makes me think that the dispose isn't being called. It used to be called on Mono 2.x though. I think there was some kind of regression. I never checked why this problem appears on Mono 3.x because this error doesn't appear on ms.net and Mono 2.x so I really think this is a bug in Mono. |
Ah, I think I understand now. Interesting. I added the finalizer to Connector, and there seems to be no However. I re-wrote NpgsqlNetworkStream to simply not call base.Dispose(), So maybe that's an approach to look at in the future, since it doesn't -Glen On Tue, Oct 29, 2013 at 9:44 AM, Francisco Figueiredo Jr. <
|
Yes, the destructors are the last ones to be called. The problem with destructors is that they are intended to release unmanaged resources only. And the stream is a managed resource. Although it relies on an unmanaged resource (socket). Also, in the destructor, .net doesn't guarantee the managed objects are available and haven't been disposed already. That's why I implemented the npgsqlnetworkstream class and used its dispose method to close the connector. |
Fix backend protocol version fallback bug
Francisco,
Here is the fix for protocol version fallback.
The problem was that, after failing to startup on version 3, the NetworkStream.Dispose() was being called from .NET, which was closing the Connector even though it had abandoned that stream and started up with a new one.
-Glen