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

[release/5.0] Split lock to prevent deadlock in Http2Stream. #47921

Merged
merged 2 commits into from
Mar 11, 2021
Merged
Changes from all commits
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 avoid lock ordering problems with Http2Connection.SyncObject

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 @@ -424,7 +428,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 @@ -1095,7 +1099,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