question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

NpgsqlException - Exception while reading from stream

See original GitHub issue

I am getting random error messages in my application log with the following stack trace. Most of the time everything is working well. I get about 10 errors and log messages like this a day in the production system. How do I figure out what is going on?

The issue

ERROR [18] 
 Npgsql.NpgsqlException (0x80004005): Exception while reading from stream ---> System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. ---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host
    at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
    --- End of inner exception stack trace ---
    at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
    at Npgsql.NpgsqlReadBuffer.<>c__DisplayClass31_0.<<Ensure>g__EnsureLong|0>d.MoveNext()
    at Npgsql.NpgsqlReadBuffer.<>c__DisplayClass31_0.<<Ensure>g__EnsureLong|0>d.MoveNext()
 --- End of stack trace from previous location where exception was thrown ---
    at Npgsql.NpgsqlConnector.<>c__DisplayClass161_0.<<ReadMessage>g__ReadMessageLong|0>d.MoveNext()
 --- End of stack trace from previous location where exception was thrown ---
    at Npgsql.NpgsqlConnector.<>c__DisplayClass161_0.<<ReadMessage>g__ReadMessageLong|0>d.MoveNext()
 --- End of stack trace from previous location where exception was thrown ---
    at Npgsql.NpgsqlDataReader.NextResult(Boolean async, Boolean isConsuming)
    at Npgsql.NpgsqlDataReader.NextResult()
    at Npgsql.NpgsqlCommand.ExecuteDbDataReader(CommandBehavior behavior, Boolean async, CancellationToken cancellationToken)
    at Npgsql.NpgsqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
    at System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior)
    at Dapper.SqlMapper.ExecuteReaderWithFlagsFallback(IDbCommand cmd, Boolean wasClosed, CommandBehavior behavior) in C:\projects\dapper\Dapper\SqlMapper.cs:line 1051
    at Dapper.SqlMapper.QueryImpl[T](IDbConnection cnn, CommandDefinition command, Type effectiveType)+MoveNext() in C:\projects\dapper\Dapper\SqlMapper.cs:line 1079
    at System.Collections.Generic.List`1.AddEnumerable(IEnumerable`1 enumerable)
    at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
    at Dapper.SqlMapper.Query[T](IDbConnection cnn, String sql, Object param, IDbTransaction transaction, Boolean buffered, Nullable`1 commandTimeout, Nullable`1 commandType) in C:\projects\dapper\Dapper\SqlMapper.cs:line 721
    at Dapper.FastCrud.SqlStatements.GenericSqlStatements`1.BatchSelect(IDbConnection connection, AggregatedSqlStatementOptions`1 statementOptions) in D:\a\1\s\Dapper.FastCrud\SqlStatements\GenericSqlStatements.cs:line 297
    at XXX.Core.Data.SqlRepository`1.FirstOrDefault(String where, Object param, String order)
    at XXXXX.App.Worker.Tasks.XXX.Process() in C:\Dropbox\dev\Src\shop\XXX\Tasks\ShopifyWebhookTask.cs:line 13
    at XXX.App.Worker.TaskBase`1.ProcessMessage(String message) in C:\Dropbox\dev\Src\shop\XXX\TaskBase.cs:line 30
    at Shop.Core.Common.Queue.BaseTaskProcessor`1.Process(QueueMessage message) in C:\Dropbox\dev\Src\shop\XXX\Queue\BaseTaskProcessor.cs:line 38
Exception message:
Stack trace:

image

Npgsql version: 4.0.10 PostgreSQL version: 10.10 Operating system: Azure Windows Function + Azure Managed PostgresSql.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:19 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
stvoidmaincommented, Jan 16, 2020

I’m using 4.1.2 now and still getting the same behaviour, gonna try to reproduce it locally and debug.

1reaction
rojicommented, Dec 2, 2019

Guys, the error message is saying that PostgreSQL closed the connection for some reason. In these cases, the PostgreSQL log almost always contains a message that provides insight into why that happened - please post those messages here and we can investigate further, otherwise there’s no enough information.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Npgsql Exception while reading from stream, Postgres
All I am doing is SELECTs. Here is the stack trace: Exception while reading from stream at Npgsql.ReadBuffer.Ensure(Int32 count, Boolean ...
Read more >
Exception while reading from stream · Issue #4532
This repo is for Npgsql ADO.NET issues only. My code is working fine while debugging. We are deploying the code in PCF. It...
Read more >
Solved: Postgresql: Exception while reading from stream
This error may happen when connection string is lacking port number. Try using server:port in connection string to Postgres database. Message 7 of...
Read more >
PostgreSQL: Exception while reading from stream
Hello! Please help me solve this error. I am try to connect PostgreSQL.Database on Greenplum. When I try to connect just a table, ......
Read more >
PostgreSQL Timeout
Npgsql.NpgsqlException Exception while reading from stream ... IOException: Unable to read data from the transport connection: A connection ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found