Repository navigation
Closed
Milestone
Description
Steps to reproduce
It requires any PostgreSQL on localhost with login password from your tests (alternatively, change connection string).
The issue
I read a data in CommandBehavior.SequentialAccess mode. An exception occurs, reading column in the middle (in my case Numeric value does not fit in a System.Decimal). My code handles this exception: reader.Dispose() or ignore row and reader.Read(). It hangs until command timeouts.
Basically any operation that in ReaderState.InResult calls ConsumeRow stucks.
Hanging stack-trace for Dispose
System.dll!System.Net.Sockets.Socket.Receive(byte[] buffer, int offset, int size, System.Net.Sockets.SocketFlags socketFlags, out System.Net.Sockets.SocketError errorCode) Line 1780 C#
System.dll!System.Net.Sockets.Socket.Receive(byte[] buffer, int offset, int size, System.Net.Sockets.SocketFlags socketFlags) Line 1741 C#
System.dll!System.Net.Sockets.NetworkStream.Read(byte[] buffer, int offset, int size) Line 508 C#
Npgsql.dll!Npgsql.NpgsqlReadBuffer.Ensure.__EnsureLong|0() Line 150 C#
Npgsql.dll!Npgsql.NpgsqlReadBuffer.Skip(long len, bool async) Line 223 C#
Npgsql.dll!Npgsql.NpgsqlSequentialDataReader.ConsumeRow(bool async) Line 300 C#
Npgsql.dll!Npgsql.NpgsqlDataReader.NextResult(bool async, bool isConsuming) Line 380 C#
Npgsql.dll!Npgsql.NpgsqlDataReader.Consume(bool async) Line 634 C#
Npgsql.dll!Npgsql.NpgsqlDataReader.Close(bool connectionClosing, bool async) Line 671 C#
Npgsql.dll!Npgsql.NpgsqlDataReader.Close() Line 645 C#
Npgsql.dll!Npgsql.NpgsqlDataReader.Dispose(bool disposing) Line 640 C#
System.Data.dll!System.Data.Common.DbDataReader.Dispose() Unknown
Hanging stack-trace for Read
System.dll!System.Net.Sockets.Socket.Receive(byte[] buffer, int offset, int size, System.Net.Sockets.SocketFlags socketFlags, out System.Net.Sockets.SocketError errorCode) Line 1780 C#
System.dll!System.Net.Sockets.Socket.Receive(byte[] buffer, int offset, int size, System.Net.Sockets.SocketFlags socketFlags) Line 1741 C#
System.dll!System.Net.Sockets.NetworkStream.Read(byte[] buffer, int offset, int size) Line 508 C#
Npgsql.dll!Npgsql.NpgsqlReadBuffer.Ensure.__EnsureLong|0() Line 139 C#
Npgsql.dll!Npgsql.NpgsqlReadBuffer.Skip(long len, bool async) Line 214 C#
Npgsql.dll!Npgsql.NpgsqlDataReader.ConsumeRow.__ConsumeRowSequential|126_0(bool async2) Line 1920 C#
Npgsql.dll!Npgsql.NpgsqlDataReader.ConsumeRow(bool async) Line 1897 C#
Npgsql.dll!Npgsql.NpgsqlDataReader.Read(bool async) Line 239 C#
Npgsql.dll!Npgsql.NpgsqlDataReader.Read() Line 161 C#
Further technical details
Npgsql version: 4.1.3.1 and 4.0.2
PostgreSQL version:10.7
Operating system: CentOS 7
Other details about my project setup:
Activity
roji commentedon Apr 24, 2020
Thanks, sequential access isn't as well-tested as it should be. You seem to have a good of idea of how things are happening, any chance you're interested in submitting a PR?
elipatov commentedon Apr 30, 2020
Here it is #2941
[-]CommandBehavior.SequentialAccess in NpgsqlDataReader causes deadlock in Npgsql 4.1.3.1[/-][+]Reading a numeric that would overflow leads to hanging[/+]Fix overflow handling when reading numeric
imb590 commentedon Sep 18, 2020
This bug is still present in 4.1.4 if the numeric value has valid scale, but causes overflows in
DecimalRaw.Multiplyhere. For example,This leaves
readerand the wholeNpgsqlConnectionin an invalid state, andreader.Dispose()and all the following attempts to use the connection fail with something like this: