Skip to content

Commit

Permalink
Merge pull request #202 from seesharper/bugfix-stackoverflow-on-dispo…
Browse files Browse the repository at this point in the history
…seasync

Ensure DisposeAsync does not cause stack overflow
  • Loading branch information
seesharper committed Dec 31, 2022
2 parents 415dc63 + 93ec480 commit 3cc0cb6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,18 @@ public async Task ShouldDisposeAsyncDisposableFromRootScope()
asyncDisposable = serviceProvider.GetService<AsyncDisposable>();
await ((IAsyncDisposable)serviceProvider).DisposeAsync();

// Call it twice to ensure only disposed once.
await ((IAsyncDisposable)serviceProvider).DisposeAsync();


Assert.Contains(asyncDisposable, disposedObjects);
Assert.Single(disposedObjects);
}

[Fact]
public async Task ShouldHandleDisposeAsyncOnServiceProvider()
{

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,16 @@ public void Dispose()
#if USE_ASYNCDISPOSABLE

public ValueTask DisposeAsync()
=> scope.DisposeAsync();
{
if (isDisposed)
{
return ValueTask.CompletedTask;
}

isDisposed = true;

return scope.DisposeAsync();
}
#endif

/// <summary>
Expand Down

0 comments on commit 3cc0cb6

Please sign in to comment.