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

Fix steaming ISB service hang #47669

Merged
merged 2 commits into from
Sep 14, 2020
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
7 changes: 5 additions & 2 deletions src/Workspaces/Remote/Core/BrokeredServiceConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,11 @@ internal static async ValueTask<TResult> InvokeStreamingServiceAsync<TResult>(
// See https://github.com/microsoft/vs-streamjsonrpc/blob/master/doc/oob_streams.md
var (clientStream, serverStream) = FullDuplexStream.CreatePair();

var writerTask = invocation(service, serverStream, cancellationToken).AsTask();
var readerTask = reader(clientStream, cancellationToken).AsTask();
// Create new tasks that both start executing, rather than invoking the delegates directly.
// If the reader started synchronously reading before the writer task started it would hang, and vice versa
// if the writer synchronously filled the buffer before the reader task started it would also hang.
var writerTask = Task.Run(async () => await invocation(service, serverStream, cancellationToken).ConfigureAwait(false), cancellationToken);
var readerTask = Task.Run(async () => await reader(clientStream, cancellationToken).ConfigureAwait(false), cancellationToken);
await Task.WhenAll(writerTask, readerTask).ConfigureAwait(false);

return readerTask.Result;
Expand Down