npgsql: Received unexpected backend message DataRow on INSERT

The issue

We have had two instances of the following error being thrown from NpgsqlDataReader.NextResult:

Exception message: "Received unexpected backend message DataRow. Please file a bug."
Stack trace:
at Npgsql.NpgsqlDataReader.NextResult(Boolean async, Boolean isConsuming)
at Npgsql.NpgsqlDataReader.NextResult()
at Npgsql.NpgsqlCommand.ExecuteDbDataReader(...)
at Npgsql.NpgsqlCommand.ExecuteDbDataReader(CommandBehavior behavior)

The error has always happened with an INSERT that also has a SELECT inside it, something like:

INSERT INTO table (column1, column2, column3) VALUES (1, 'a', (SELECT COALESCE(MAX(column3), -1) FROM table WHERE column1 = @someId)+1)

That may be pure coincidence but I wanted to mention it.

Further technical details

Npgsql version: 4.0.0-rc1 PostgreSQL version: 9.6 Operating system: Windows Server 2012 R2

Other details about my project setup: We saw this error happen as we started out a rollout of a new version of our software. We have just upgraded to Npgsql 4.0.1 so we will see if we still get this error after that. I couldn’t find any spicific issue between 4.0.0-rc1 and 4.0.1 that would have fixed this (though there were a lot of changes) so I wanted to just open this to be safe and give you a heads up.

If you need any more details or anything please let me know.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 16 (7 by maintainers)

Most upvoted comments

@roji I will try to reproduce it with a simple program. I have never seen these exception in our testing environment but maybe thats because there is way less load on the system.

Meanwhile here is my connection string: Server=xxx;Port=5432;Database=xxx;User Id=xxx;Password=xxx;Keepalive=30;CommandTimeout=1800;Timeout=30;

We are using dapper and also polly for the retry logic. Here is a full stacktrace:


Npgsql.NpgsqlException: Received backend message NoData while expecting ParseCompleteMessage. Please file a bug. (Npgsql.NpgsqlException (0x80004005): Received backend message NoData while expecting ParseCompleteMessage. Please file a bug.
   at Npgsql.NpgsqlDataReader.<NextResult>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.<ExecuteDbDataReader>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 Dapper.SqlMapper.ExecuteReaderWithFlagsFallback(IDbCommand cmd, Boolean wasClosed, CommandBehavior behavior)
   at Dapper.SqlMapper.QueryRowImpl[T](IDbConnection cnn, Row row, CommandDefinition& command, Type effectiveType)
   at Dapper.SqlMapper.QuerySingle[T](IDbConnection cnn, String sql, Object param, IDbTransaction transaction, Nullable`1 commandTimeout, Nullable`1 commandType)
   at xxx.data.msgprocessor.MsgProcessorRepository.<>c__DisplayClass4_0.<GetTagIdFromExternalId>b__0(IDbConnection c)
   at xxx.data.BaseRepository.<>c__DisplayClass3_0`1.<WithConnection>b__0()
   at Polly.Policy.<>c__DisplayClass150_0`1.<Execute>b__0(Context ctx, CancellationToken ct)
   at Polly.Policy.<>c__DisplayClass143_0`1.<ExecuteInternal>b__0(Context ctx, CancellationToken ct)
   at Polly.RetrySyntax.<>c__DisplayClass12_1.<WaitAndRetry>b__1(Context ctx, CancellationToken ct)
   at Polly.Retry.RetryEngine.Implementation[TResult](Func`3 action, Context context, CancellationToken cancellationToken, IEnumerable`1 shouldRetryExceptionPredicates, IEnumerable`1 shouldRetryResultPredicates, Func`1 policyStateFactory)
   at Polly.RetrySyntax.<>c__DisplayClass12_0.<WaitAndRetry>b__0(Action`2 action, Context context, CancellationToken cancellationToken)
   at Polly.Policy.ExecuteInternal[TResult](Func`3 action, Context context, CancellationToken cancellationToken)
   at Polly.Policy.Execute[TResult](Func`3 action, Context context, CancellationToken cancellationToken)
   at Polly.Policy.Execute[TResult](Func`1 action)
   at xxx.data.msgprocessor.MsgProcessorRepository.GetTagIdFromExternalId(Int32 deviceId, String tagExternalId, Int32 tagType, Boolean& isNew)
   at xxx.msgprocessor.DriverMsgHandler.ProcessMessage(Object message) in D:\gitlab-runner\builds\aa962e52\0\xxx\xxxserver\xxx.msgprocessor\handler\DriverMsgHandler.cs:line 63)
at Npgsql.NpgsqlDataReader+<NextResult>d__46.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task)
at Npgsql.NpgsqlDataReader.NextResult()
at Npgsql.NpgsqlCommand+<ExecuteDbDataReader>d__100.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task)
at Npgsql.NpgsqlCommand.ExecuteDbDataReader(System.Data.CommandBehavior)
at Dapper.SqlMapper.ExecuteReaderWithFlagsFallback(System.Data.IDbCommand, Boolean, System.Data.CommandBehavior)
at Dapper.SqlMapper.QueryRowImpl[T](System.Data.IDbConnection, Row, Dapper.CommandDefinition ByRef, System.Type)
at Dapper.SqlMapper.QuerySingle[T](System.Data.IDbConnection, System.String, System.Object, System.Data.IDbTransaction, System.Nullable`1[System.Int32], System.Nullable`1[System.Data.CommandType])
at xxx.data.msgprocessor.MsgProcessorRepository+<>c__DisplayClass4_0.<GetTagIdFromExternalId>b__0(System.Data.IDbConnection)
at xxx.data.BaseRepository+<>c__DisplayClass3_0`1.<WithConnection>b__0()
at Polly.Policy+<>c__DisplayClass150_0`1.<Execute>b__0(Polly.Context, System.Threading.CancellationToken)
at Polly.Policy+<>c__DisplayClass143_0`1.<ExecuteInternal>b__0(Polly.Context, System.Threading.CancellationToken)
at Polly.RetrySyntax+<>c__DisplayClass12_1.<WaitAndRetry>b__1(Polly.Context, System.Threading.CancellationToken)
at Polly.Retry.RetryEngine.Implementation[TResult](System.Func`3[Polly.Context,System.Threading.CancellationToken,TResult], Polly.Context, System.Threading.CancellationToken, System.Collections.Generic.IEnumerable`1[Polly.ExceptionPredicate], System.Collections.Generic.IEnumerable`1[Polly.ResultPredicate`1[TResult]], System.Func`1[Polly.Retry.IRetryPolicyState`1[TResult]])
at Polly.RetrySyntax+<>c__DisplayClass12_0.<WaitAndRetry>b__0(System.Action`2[Polly.Context,System.Threading.CancellationToken], Polly.Context, System.Threading.CancellationToken)
at Polly.Policy.ExecuteInternal[TResult](System.Func`3[Polly.Context,System.Threading.CancellationToken,TResult], Polly.Context, System.Threading.CancellationToken)
at Polly.Policy.Execute[TResult](System.Func`3[Polly.Context,System.Threading.CancellationToken,TResult], Polly.Context, System.Threading.CancellationToken)
at Polly.Policy.Execute[TResult](System.Func`1[TResult])
at xxx.data.msgprocessor.MsgProcessorRepository.GetTagIdFromExternalId(Int32, System.String, Int32, Boolean ByRef)
at xxx.msgprocessor.DriverMsgHandler.ProcessMessage(System.Object) in D:\gitlab-runner\builds\aa962e52\0\xxx\xxxserver\xxx.msgprocessor\handler\DriverMsgHandler.cs:line 63
at xxx.msgprocessor.DeviceInQueue.ProcessMessage(System.Object) in D:\gitlab-runner\builds\aa962e52\0\xxx\xxxserver\xxx.msgprocessor\queues\DeviceInQueue.cs:line 80
at System.Dynamic.UpdateDelegates.UpdateAndExecuteVoid2[T0,T1](System.Runtime.CompilerServices.CallSite, T0, T1)
at xxx.msgprocessor.DeviceInQueue.<StartConsumer>b__12_0() in D:\gitlab-runner\builds\aa962e52\0\xxx\xxxserver\xxx.msgprocessor\queues\DeviceInQueue.cs:line 56
at System.Threading.Tasks.Task.Execute()
at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
at System.Threading.Tasks.Task.ExecuteWithThreadLocal(System.Threading.Tasks.Task ByRef)
at System.Threading.Tasks.Task.ExecuteEntry(Boolean)
at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
at System.Threading.ThreadHelper.ThreadStart(System.Object)