Skip to content

Commit

Permalink
Fix steaming ISB service hang (#47669)
Browse files Browse the repository at this point in the history
* Fix steaming ISB service hang

* Fix comment
  • Loading branch information
tmat authored Sep 14, 2020
1 parent a30cc93 commit 9499caf
Showing 1 changed file with 5 additions and 2 deletions.
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

0 comments on commit 9499caf

Please sign in to comment.