Hardik Dobariya
Hardik Dobariya

Reputation: 349

Exception while reading from stream in npgsql

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 ---

Upvotes: 6

Views: 13660

Answers (1)

andrew.fox
andrew.fox

Reputation: 7941

We had similar problem with version 4.0.4 (well any 4.x really).

It turned out that one of the columns that were already stored in database contained invalid characters or was somehow corrupted.

Simple update <tab> set <col> = '' where id = <id> for that one column fixed the Exception while reading from the stream error message.

PS. Restoring the date without suspicious UTF-8 characters didn't cause the problem to reappear.

Upvotes: 0

Related Questions