Background
Since upgrading from Npgsql 2 to Npgsql 3, I started getting EndOfStreamExceptions every now and then:
Message:
Name: EndOfStreamException
Message: Attempted to read past the end of the stream.
Source: Npgsql
Properties:
TargetSite = Void Ensure(Int32)
HResult = -2147024858
Stack Trace:
at Npgsql.NpgsqlBuffer.Ensure(Int32 count)
at Npgsql.NpgsqlConnector.DoReadSingleMessage(DataRowLoadingMode dataRowLoadingMode, Boolean returnNullForAsyncMessage, Boolean isPrependedMessage)
at Npgsql.NpgsqlConnector.ReadSingleMessage(DataRowLoadingMode dataRowLoadingMode, Boolean returnNullForAsyncMessage)
at Npgsql.NpgsqlCommand.Execute(CommandBehavior behavior)
at Npgsql.NpgsqlCommand.ExecuteDbDataReaderInternal(CommandBehavior behavior)
- It seems to happen if I don't do anything in the application (no PostgreSQL activity) but then come back and do something (triggering a new PostgreSQL query) after maybe 15 or 20 minutes.
- This happens when I run
cmd.ExecuteReader().
- The connection string looks like
Server=REMOVED;Port=REMOVED;User Id=REMOVED;Password=REMOVED;Database=REMOVED;SSL Mode=Require;
- Running
SELECT VERSION() produces PostgreSQL 9.3.10 on x86_64-unknown-linux-gnu, compiled by gcc (Ubuntu 4.8.2-19ubuntu1) 4.8.2, 64-bit.
- The problem didn't seem to happen in Npgsql 2.1.2 or 2.2.7 when I tested, but it did happen in 3.0.0, 3.0.5 and 3.1.0-alpha6.
Similarly, when I use pgAdmin III to connect to the same database, it produces an EOF (end-of-file) error if I haven't done anything with the connection for about 15 minutes. So I believe this problem is caused by some sort of connection timeout (15 minutes) between my computer and the database server.
Not sure why the problem only started happening in Npgsql 3. My DB commands and queries don't run for 15 minutes, so maybe it's because of connection pooling behaviour in Npgsql 3?
I worked around this in Npgsql 3 by enabling a 10-minute keep-alive in the connection string (Keepalive=600). So far so good.
NullReferenceException
Since applying the Keepalive workaround shown above, things have been mostly fine. However, I once ran into the following exception using Npgsql 3.0.5 after not doing anything in the application for a while again:
Name: NullReferenceException
Message: Object reference not set to an instance of an object.
Source: Npgsql
Properties:
TargetSite = System.IDisposable StartUserAction(Npgsql.ConnectorState)
HResult = -2147467261
Stack Trace:
at Npgsql.NpgsqlConnector.StartUserAction(ConnectorState newState)
at Npgsql.NpgsqlCommand.ExecuteDbDataReaderInternal(CommandBehavior behavior)
I haven't been able to reproduce it again. I'm guessing this could be an Npgsql bug since NullReferenceException isn't really meaningful to users of the library.
Background
Since upgrading from Npgsql 2 to Npgsql 3, I started getting
EndOfStreamExceptions every now and then:cmd.ExecuteReader().Server=REMOVED;Port=REMOVED;User Id=REMOVED;Password=REMOVED;Database=REMOVED;SSL Mode=Require;SELECT VERSION()producesPostgreSQL 9.3.10 on x86_64-unknown-linux-gnu, compiled by gcc (Ubuntu 4.8.2-19ubuntu1) 4.8.2, 64-bit.Similarly, when I use pgAdmin III to connect to the same database, it produces an
EOF(end-of-file) error if I haven't done anything with the connection for about 15 minutes. So I believe this problem is caused by some sort of connection timeout (15 minutes) between my computer and the database server.Not sure why the problem only started happening in Npgsql 3. My DB commands and queries don't run for 15 minutes, so maybe it's because of connection pooling behaviour in Npgsql 3?
I worked around this in Npgsql 3 by enabling a 10-minute keep-alive in the connection string (
Keepalive=600). So far so good.NullReferenceExceptionSince applying the
Keepaliveworkaround shown above, things have been mostly fine. However, I once ran into the following exception using Npgsql 3.0.5 after not doing anything in the application for a while again:I haven't been able to reproduce it again. I'm guessing this could be an Npgsql bug since
NullReferenceExceptionisn't really meaningful to users of the library.