From 22b2d9c00169f9ca02f6438b209307a5ac84fa96 Mon Sep 17 00:00:00 2001 From: Tomas Matousek Date: Sun, 13 Sep 2020 18:27:14 -0700 Subject: [PATCH 1/2] Fix steaming ISB service hang --- src/Workspaces/Remote/Core/BrokeredServiceConnection.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Workspaces/Remote/Core/BrokeredServiceConnection.cs b/src/Workspaces/Remote/Core/BrokeredServiceConnection.cs index 58787a154dccc..d42de722f4647 100644 --- a/src/Workspaces/Remote/Core/BrokeredServiceConnection.cs +++ b/src/Workspaces/Remote/Core/BrokeredServiceConnection.cs @@ -137,8 +137,11 @@ internal static async ValueTask InvokeStreamingServiceAsync( // 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 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; From 16bc7c5ea8ba2759d1b9155c25f911c17af5636a Mon Sep 17 00:00:00 2001 From: Tomas Matousek Date: Sun, 13 Sep 2020 18:28:15 -0700 Subject: [PATCH 2/2] Fix comment --- src/Workspaces/Remote/Core/BrokeredServiceConnection.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Workspaces/Remote/Core/BrokeredServiceConnection.cs b/src/Workspaces/Remote/Core/BrokeredServiceConnection.cs index d42de722f4647..484d6f7276d21 100644 --- a/src/Workspaces/Remote/Core/BrokeredServiceConnection.cs +++ b/src/Workspaces/Remote/Core/BrokeredServiceConnection.cs @@ -137,7 +137,7 @@ internal static async ValueTask InvokeStreamingServiceAsync( // See https://github.com/microsoft/vs-streamjsonrpc/blob/master/doc/oob_streams.md var (clientStream, serverStream) = FullDuplexStream.CreatePair(); - // Create new tasks that both start executing, rather than the delegates directly. + // 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);