Queries that contain multiple statements unexpectedly throw timeout errors in .NET 8.0. By multiple statements, I mean statements separated by a semi-colon that should be run in a single call to Execute/Query. It occurs randomly in both our staging and production environments (in AWS using RDS) but I can also replicate the error locally. If I split these queries into two separate calls to Execute/Query, they work fine and I don't experience the issue.
The exception is as follows:
Npgsql.NpgsqlException (0x80004005): Exception while reading from stream
---> System.TimeoutException: Timeout during reading attempt
and the stack trace that represents these errors typically looks as follows:
Npgsql.NpgsqlException (0x80004005): Exception while reading from stream
---> System.TimeoutException: Timeout during reading attempt
at Npgsql.Internal.NpgsqlReadBuffer.<Ensure>g__EnsureLong|55_0(NpgsqlReadBuffer buffer, Int32 count, Boolean async, Boolean readingNotifications)
at System.Runtime.CompilerServices.PoolingAsyncValueTaskMethodBuilder`1.StateMachineBox`1.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token)
at Npgsql.Internal.NpgsqlConnector.ReadMessageLong(Boolean async, DataRowLoadingMode dataRowLoadingMode, Boolean readingNotifications, Boolean isReadingPrependedMessage)
at System.Runtime.CompilerServices.PoolingAsyncValueTaskMethodBuilder`1.StateMachineBox`1.System.Threading.Tasks.Sources.IValueTaskSource<TResult>.GetResult(Int16 token)
at Npgsql.Internal.NpgsqlConnector.ReadMessageLong(Boolean async, DataRowLoadingMode dataRowLoadingMode, Boolean readingNotifications, Boolean isReadingPrependedMessage)
at System.Runtime.CompilerServices.PoolingAsyncValueTaskMethodBuilder`1.StateMachineBox`1.System.Threading.Tasks.Sources.IValueTaskSource<TResult>.GetResult(Int16 token)
at Npgsql.NpgsqlDataReader.NextResult(Boolean async, Boolean isConsuming, CancellationToken cancellationToken)
at Npgsql.NpgsqlDataReader.NextResult(Boolean async, Boolean isConsuming, CancellationToken cancellationToken)
at Npgsql.NpgsqlCommand.ExecuteReader(Boolean async, CommandBehavior behavior, CancellationToken cancellationToken)
at Npgsql.NpgsqlCommand.ExecuteReader(Boolean async, CommandBehavior behavior, CancellationToken cancellationToken)
at Npgsql.NpgsqlCommand.ExecuteNonQuery(Boolean async, CancellationToken cancellationToken)
at Dapper.SqlMapper.ExecuteCommand(IDbConnection cnn, CommandDefinition& command, Action`2 paramReader) in /_/Dapper/SqlMapper.cs:line 2965
at Dapper.SqlMapper.ExecuteImpl(IDbConnection cnn, CommandDefinition& command) in /_/Dapper/SqlMapper.cs:line 656
Steps to reproduce
I have attached a tiny console
npgbugrepro.zip
project that demonstrates this issue. I can get it to occur 100% of the time in my local environment. The DDL for the tables is as follows:
CREATE TABLE public.sessions (
session_id text NOT NULL,
user_id int4 NOT NULL,
total int4 DEFAULT 1 NOT NULL,
last_update_date timestamptz DEFAULT now() NOT NULL,
creation_date timestamptz DEFAULT now() NOT NULL,
ip_address text NULL,
CONSTRAINT "PK_sessions" PRIMARY KEY (session_id)
);
CREATE UNIQUE INDEX sess_session_id_user_id_last_update_date_idx ON public.sessions USING btree (user_id, session_id);
CREATE TABLE public.page_views (
session_id text NOT NULL,
user_id int4 NOT NULL,
url text NULL,
full_url text NULL,
creation_date timestamptz DEFAULT now() NOT NULL,
ip_address text NULL
);
CREATE INDEX pv_user_id_idx ON public.page_views USING btree (user_id);
Further technical details
Npgsql version: 8.0.4
PostgreSQL version: 16.3
Operating system: Windows Server 2022 but seen it in RDS on AWS.
Other details about my project setup: Using dapper for queries but no ORM's.
Any ideas on what is happening here? Thank you!
Queries that contain multiple statements unexpectedly throw timeout errors in .NET 8.0. By multiple statements, I mean statements separated by a semi-colon that should be run in a single call to Execute/Query. It occurs randomly in both our staging and production environments (in AWS using RDS) but I can also replicate the error locally. If I split these queries into two separate calls to Execute/Query, they work fine and I don't experience the issue.
The exception is as follows:
and the stack trace that represents these errors typically looks as follows:
Steps to reproduce
I have attached a tiny console
npgbugrepro.zip
project that demonstrates this issue. I can get it to occur 100% of the time in my local environment. The DDL for the tables is as follows:
Further technical details
Npgsql version: 8.0.4
PostgreSQL version: 16.3
Operating system: Windows Server 2022 but seen it in RDS on AWS.
Other details about my project setup: Using dapper for queries but no ORM's.
Any ideas on what is happening here? Thank you!