Skip to content

Commit 1eb884e

Browse files
authored
Merge pull request #1571 from microsoft/agents/diagnose-non-deterministic-failure
AsyncCrossProcessMutex: Fix foreground thread leak causing non-deterministic test host exit failure
2 parents 7f47bc6 + b263564 commit 1eb884e

2 files changed

Lines changed: 3 additions & 2 deletions

File tree

src/Microsoft.VisualStudio.Threading/AsyncCrossProcessMutex.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public AsyncCrossProcessMutex(string name)
5656
Requires.NotNullOrEmpty(name);
5757
this.namedMutexOwner = new Thread(this.MutexOwnerThread, 256 * 1024)
5858
{
59+
IsBackground = true,
5960
Name = $"{nameof(AsyncCrossProcessMutex)}-{name}",
6061
};
6162
this.mutex = new Mutex(false, name);

test/Microsoft.VisualStudio.Threading.Tests/AsyncCrossProcessMutexTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public async Task TryEnterAsync_Reentrancy()
7272
public async Task EnterAsync_Contested()
7373
{
7474
// We don't allow attempted reentrancy, so create a new mutex object to use for the contested locks.
75-
AsyncCrossProcessMutex mutex2 = new(this.mutex.Name);
75+
using AsyncCrossProcessMutex mutex2 = new(this.mutex.Name);
7676

7777
// Acquire and hold the mutex so that we can test timeout behavior.
7878
using (AsyncCrossProcessMutex.LockReleaser releaser = await this.mutex.EnterAsync())
@@ -95,7 +95,7 @@ public async Task EnterAsync_Contested()
9595
public async Task TryEnterAsync_Contested()
9696
{
9797
// We don't allow attempted reentrancy, so create a new mutex object to use for the contested locks.
98-
AsyncCrossProcessMutex mutex2 = new(this.mutex.Name);
98+
using AsyncCrossProcessMutex mutex2 = new(this.mutex.Name);
9999

100100
// Acquire and hold the mutex so that we can test timeout behavior.
101101
using (AsyncCrossProcessMutex.LockReleaser? releaser = await this.mutex.TryEnterAsync(Timeout.InfiniteTimeSpan))

0 commit comments

Comments
 (0)