4
votes

We have a table having one of the columns as a text datatype and having only 3 records. We execute an Update query on text column using ExecuteNonQuery() and it throws an error "Exception while reading from the stream". Error occurs randomly which means some times the query is executed and sometimes it throws an error but the maximum ratio is of error like it throws error 9 times out of 10. We are using Npgsql -Version 4.0.4 and PostgreSQL version 11.1 running on windows 2012 R2 . Also, we tried setting up the timeout as 0 but the error is thrown immediately so it is not related to timeout error as well. Below is our exception.

   at Npgsql.NpgsqlReadBuffer.<>c__DisplayClass31_0.<g__EnsureLong|0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Npgsql.NpgsqlConnector.<>c__DisplayClass161_0.<g__ReadMessageLong|0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Npgsql.NpgsqlDataReader.d__46.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Npgsql.NpgsqlDataReader.NextResult()
   at Npgsql.NpgsqlCommand.d__100.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Npgsql.NpgsqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
   at Npgsql.NpgsqlCommand.ExecuteReader()
   at Npgsql.PostgresDatabaseInfo.d__13.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Npgsql.PostgresDatabaseInfo.d__11.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Npgsql.PostgresDatabaseInfoFactory.d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Npgsql.NpgsqlDatabaseInfo.d__79.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Npgsql.NpgsqlConnector.d__150.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Npgsql.NpgsqlConnector.d__149.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Npgsql.ConnectorPool.d__19.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Npgsql.NpgsqlConnection.<>c__DisplayClass32_0.<g__OpenLong|0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Npgsql.NpgsqlConnection.Open()
   at DataAccessLayer.Providers.Executors.PostgreSQL.ExecuteQuery(PreparedStatement`1 preparedStatement, Int32 timeout) in C:\code\Framework\DataAccessLayer\Providers\Executors\PostgreSQL.cs:line 64
   at DataAccessLayer.Providers.PostgreSQL.ExecuteQuery(IExecuteQuerySupport command, Int32 timeout) in C:\main\code\Framework\DataAccessLayer\Providers\Modules\PostgreSQLServer.cs:line 26
   at BAL.Base.RolesManagement.Roles.GetDatabaseRole(Int64 userID) in C:\main\code\BusinessAccessLayer\BAL\Base\RolesManagement\Roles.cs:line 398
   at API.Controllers.MyWorkspacesController.ConnectGroup(Int64 groupID) in C:\main\code\Web\API\Controllers\MyWorkspacesController.cs:line 390
   --- End of exception stack trace ---
    Message : Unable to read data from the transport connection: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
StackTrace :    at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
   at Npgsql.NpgsqlReadBuffer.<>c__DisplayClass31_0.<g__EnsureLong|0>d.MoveNext()
    --- End of inner exception stack trace --- 
    Message : A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
StackTrace :    at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
   --- End of inner exception stack trace ---
Your message includes a stack trace, but not the exception message itself - you indicate that it could be a timeout message, but can you please confirm? If so, please try turning on keepalives as described here: npgsql.org/doc/keepalive.html - Shay Rojansky
@ShayRojansky: The error says "Exception while reading from the stream" and the mentioned above is the stack trace. I meant to say it is not a timeout issue because the error is thrown immediately so even setting timeout will not work. Even keepalive is not an issue because it's throwing the error immediately without waiting for a time. - Hardik Dobariya
In general, "Exception while reading from the stream" isn't the complete exception message. Can you make sure you're doing a ToString() on the exception message and posting the result? - Shay Rojansky
The exception message is "Exception while reading from the stream" and its stack trace is as mentioned above. This is the only information we are logging in our error system.We are not logging the inner stack trace - Hardik Dobariya