Skip to content

Commit 0190ea1

Browse files
committed
Fix possible race condition with unprepare
1 parent 01aaadf commit 0190ea1

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/Npgsql/NpgsqlCommand.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -783,11 +783,12 @@ async Task Unprepare(bool async, CancellationToken cancellationToken = default)
783783

784784
foreach (var batchCommand in InternalBatchCommands)
785785
{
786-
if (batchCommand.PreparedStatement?.State == PreparedState.BeingUnprepared)
786+
if (batchCommand.IsPrepared)
787787
{
788788
Expect<CloseCompletedMessage>(await connector.ReadMessage(async).ConfigureAwait(false), connector);
789789

790790
var pStatement = batchCommand.PreparedStatement;
791+
Debug.Assert(pStatement is not null);
791792
pStatement.CompleteUnprepare();
792793

793794
if (!pStatement.IsExplicit)
@@ -1144,7 +1145,6 @@ async Task SendClose(NpgsqlConnector connector, bool async, CancellationToken ca
11441145
await new TaskSchedulerAwaitable(ConstrainedConcurrencyScheduler);
11451146

11461147
await connector.WriteClose(StatementOrPortal.Statement, batchCommand.StatementName, async, cancellationToken).ConfigureAwait(false);
1147-
batchCommand.PreparedStatement!.State = PreparedState.BeingUnprepared;
11481148
i++;
11491149
}
11501150

0 commit comments

Comments
 (0)