Sunday, December 04, 2011

Fixed! LOG: unexpected EOF on client connection

Hi all!

Since we implemented connection pool in Npgsql, we received some complaints about EOF log messages being generated on Postgresql logs when using Npgsql. This was caused by Npgsql not sending the proper terminate message to Postgresql on pooled connections when the application terminated or more specifically when the assembly was unloaded.
This is a long time problem with Npgsql connection pool. I even talked about it in the past.

Up to now, I had no idea about how to fix that as I wasn't able to close the connections in the pool. When I tried to put a finalizer in NpgsqlConnectorPool, which would be triggered when the assembly was unloaded, I received object already disposed exceptions when trying to send something to the stream.
That's when I came up with the "excellent" idea of subclassing the networkstream class and override its Dispose method so that I could send the postgresql terminate message before it was disposed! :)

It worked like a charm! Now, Npgsql doesn't produce EOF log messages anymore.
The current implementation isn't very beautiful, as it is a simple callback to NpgsqlConnector.Close() method, but it works ok and there is no need to manage with any other finalizer.

Next Npgsql version will have this fix and finally we will get rid of this strange log message.


Hugo Rafael Lesme Marquez said...

Olá Francisco!

Vc tem uma ideia de quando estaría sendo lançado a versão com o fix ?

tekun said...

gracias, este es un error que desde hace mucho quería eliminar

Vladica Savić said...

When we can expect new Npgsql release with this bug fixed?

Vladica Savić said...

When we can expect new Npgsql release with this bug fixed?

Francisco Figueiredo Jr. said...

Hi all!

Sorry for late response....

I hope to get a new beta release with this fix in the next couple of weeks.

Thanks all for your feedback!