Skip to content

Commit

Permalink
Bugfix SQLServerMemory semaphore not released properly (#883)
Browse files Browse the repository at this point in the history
## Motivation and Context (Why the change? What's the scenario?)

A simple bugfix for SQLServerMemory. The semaphore wasn't released when
"is ready" changes from "false" to "true" while the code was waiting for
the semaphore. Meaning if specifically 3 or more tasks run into that
code at the same time, the third task as well as all others are gonna be
stuck in a deadlock waiting for the semaphore. This only happens during
the first initialization, since subsequent calls will leave before
waiting for the semaphore.
  • Loading branch information
snakex64 authored Nov 11, 2024
1 parent b67dfe7 commit ad4a996
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion extensions/SQLServer/SQLServer/SqlServerMemory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -397,10 +397,11 @@ private async Task InitAsync(CancellationToken cancellationToken)
if (this._isReady) { return; }

await this._initSemaphore.WaitAsync(cancellationToken).ConfigureAwait(false);
if (this._isReady) { return; }

try
{
if (this._isReady) { return; }

await this.CacheSqlServerMajorVersionNumberAsync(cancellationToken).ConfigureAwait(false);
await this.CreateTablesIfNotExistsAsync(cancellationToken).ConfigureAwait(false);
this._isReady = true;
Expand Down

0 comments on commit ad4a996

Please sign in to comment.