X Tutup
Skip to content

Improve NpgsqlDataReader resilience to (unsupported) concurrent usage #6264

@mitrydates

Description

@mitrydates

After update from older version it's occasionally crushing our server, we did investigation and collected memory dumps:

7f66a91f6cc0 16,368,298  2,095,142,144 System.NullReferenceException

So it contains 16Milions of exception

Stack trace for all 16m exceptions:
00007F2583FFB160 00007F66B1163ECC Npgsql!Npgsql.Internal.NpgsqlConnector+<ReadMessageLong>d__235.MoveNext()+0x2ac 00007F2583FFB290 00007F66B16F8E3D System_Private_CoreLib!System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()+0x1d 00007F2583FFB2A0 00007F66B4344DAA System_Private_CoreLib!System.Threading.Tasks.Sources.ManualResetValueTaskSourceCore1[[System.__Canon, System.Private.CoreLib]].ThrowForFailedGetResult()+0x3a
00007F2583FFB2C0 00007F66B1643C38 System_Private_CoreLib!System.Threading.Tasks.Sources.ManualResetValueTaskSourceCore1[[System.__Canon, System.Private.CoreLib]].GetResult(Int16)+0x38 00007F2583FFB2E0 00007F66B4344D06 System_Private_CoreLib!System.Runtime.CompilerServices.PoolingAsyncValueTaskMethodBuilder1+StateMachineBox1[[System.__Canon, System.Private.CoreLib],[System.__Canon, System.Private.CoreLib]].System.Threading.Tasks.Sources.IValueTaskSource<TResult>.GetResult(Int16)+0x56 00007F2583FFB310 00007F66B1163DCA Npgsql!Npgsql.Internal.NpgsqlConnector+<ReadMessageLong>d__235.MoveNext()+0x1aa 00007F2583FFB450 00007F66B16F8E3D System_Private_CoreLib!System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()+0x1d 00007F2583FFB460 00007F66B4344DAA System_Private_CoreLib!System.Threading.Tasks.Sources.ManualResetValueTaskSourceCore1[[System.__Canon, System.Private.CoreLib]].ThrowForFailedGetResult()+0x3a
00007F2583FFB480 00007F66B1643C38 System_Private_CoreLib!System.Threading.Tasks.Sources.ManualResetValueTaskSourceCore1[[System.__Canon, System.Private.CoreLib]].GetResult(Int16)+0x38 00007F2583FFB4A0 00007F66B4344D06 System_Private_CoreLib!System.Runtime.CompilerServices.PoolingAsyncValueTaskMethodBuilder1+StateMachineBox`1[[System.__Canon, System.Private.CoreLib],[System.__Canon, System.Private.CoreLib]].System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16)+0x56
00007F2583FFB4D0 00007F66B1FD1FE2 Npgsql!Npgsql.NpgsqlDataReader+d__52.MoveNext()+0x2202
00007F2583FFB4C0 00007F66B16F8E3D System_Private_CoreLib!System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()+0x1d
00007F2583FFB4D0 00007F66B1FD23F6 Npgsql!Npgsql.NpgsqlDataReader+d__52.MoveNext()+0x2616
00007F2583FFB5F0 00007F66B16F8E3D System_Private_CoreLib!System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()+0x1d
00007F2583FFB600 00007F66B32CA78B System_Private_CoreLib!System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task, System.Threading.Tasks.ConfigureAwaitOptions)+0xdb
00007F2583FFB630 00007F66B3153D03 Npgsql!Npgsql.NpgsqlDataReader+d__73.MoveNext()+0x2a3

`
problem is:
NpgsqlDataReader.Consume(bool async, Exception? firstException = null)

        while (!Connector.IsBroken)
        {
            try
            {
                if (!(_isSchemaOnly
                        ? await NextResultSchemaOnly(async, isConsuming: true).ConfigureAwait(false)
                        : await NextResult(async, isConsuming: true).ConfigureAwait(false)))
                {
                    break;
                }
            }
            catch (Exception e)
            {
                exceptions ??= [];
                exceptions.Add(e);
            }
        }

Its infinite loop collecting same exception,

any ideas how to fix?

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    X Tutup