Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split lock to prevent deadlock in Http2Stream. #47769

Merged
merged 4 commits into from
Feb 8, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ private sealed class Http2Stream : IValueTaskSource, IHttpHeadersHandler, IHttpT
private int _pendingWindowUpdate;
private CreditWaiter? _creditWaiter;
private int _availableCredit;
private readonly object _creditSyncObject = new object(); // split from SyncObject to mitigate deadlock in OnWindowUpdate.
ManickaP marked this conversation as resolved.
Show resolved Hide resolved

private StreamCompletionState _requestCompletionState;
private StreamCompletionState _responseCompletionState;
Expand Down Expand Up @@ -349,11 +350,14 @@ private void Complete()

_connection.RemoveStream(this);

CreditWaiter? w = _creditWaiter;
if (w != null)
lock (_creditSyncObject)
{
w.Dispose();
_creditWaiter = null;
CreditWaiter? waiter = _creditWaiter;
if (waiter != null)
{
waiter.Dispose();
_creditWaiter = null;
}
}
}

Expand Down Expand Up @@ -421,7 +425,7 @@ private void Cancel()

public void OnWindowUpdate(int amount)
{
lock (SyncObject)
lock (_creditSyncObject)
{
_availableCredit = checked(_availableCredit + amount);
if (_availableCredit > 0 && _creditWaiter != null)
Expand Down Expand Up @@ -1219,7 +1223,7 @@ private async ValueTask SendDataAsync(ReadOnlyMemory<byte> buffer, CancellationT
while (buffer.Length > 0)
{
int sendSize = -1;
lock (SyncObject)
lock (_creditSyncObject)
{
if (_availableCredit > 0)
{
Expand Down