提交 d4a64313 编写于 作者: S Sam Harwell

Add workaround for AsyncSemaphore disposal problems

This is a workaround for #18563. See #19042 for a follow-up task to remove
this workaround.
上级 f1864f80
...@@ -48,7 +48,7 @@ public static async Task<RemoteHostClient> CreateAsync(Workspace workspace, bool ...@@ -48,7 +48,7 @@ public static async Task<RemoteHostClient> CreateAsync(Workspace workspace, bool
{ {
_inprocServices = inprocServices; _inprocServices = inprocServices;
_rpc = new JsonRpc(stream, stream, target: this); _rpc = new JsonRpc(new JsonRpcMessageHandler(stream, stream), target: this);
_rpc.JsonSerializer.Converters.Add(AggregateJsonConverter.Instance); _rpc.JsonSerializer.Converters.Add(AggregateJsonConverter.Instance);
// handle disconnected situation // handle disconnected situation
......
...@@ -28,7 +28,7 @@ internal class JsonRpcClient : IDisposable ...@@ -28,7 +28,7 @@ internal class JsonRpcClient : IDisposable
var target = useThisAsCallback ? this : callbackTarget; var target = useThisAsCallback ? this : callbackTarget;
_cancellationToken = cancellationToken; _cancellationToken = cancellationToken;
_rpc = new JsonRpc(stream, stream, target); _rpc = new JsonRpc(new JsonRpcMessageHandler(stream, stream), target);
_rpc.JsonSerializer.Converters.Add(AggregateJsonConverter.Instance); _rpc.JsonSerializer.Converters.Add(AggregateJsonConverter.Instance);
_rpc.Disconnected += OnDisconnected; _rpc.Disconnected += OnDisconnected;
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.IO;
using StreamJsonRpc;
namespace Microsoft.VisualStudio.LanguageServices.Remote
{
// This is a workaround for a limitation in vs-threading.
// https://github.com/dotnet/roslyn/issues/19042
internal class JsonRpcMessageHandler : HeaderDelimitedMessageHandler
{
public JsonRpcMessageHandler(Stream sendingStream, Stream receivingStream)
: base(sendingStream, receivingStream)
{
}
protected override void Dispose(bool disposing)
{
// Do not call base.Dispose. We do not want the AsyncSemaphore instances to be disposed due to a race
// condition.
if (disposing)
{
ReceivingStream?.Dispose();
SendingStream?.Dispose();
}
}
}
}
...@@ -106,7 +106,7 @@ private static async Task RegisterWorkspaceHostAsync(Workspace workspace, Remote ...@@ -106,7 +106,7 @@ private static async Task RegisterWorkspaceHostAsync(Workspace workspace, Remote
_hostGroup = hostGroup; _hostGroup = hostGroup;
_timeout = TimeSpan.FromMilliseconds(workspace.Options.GetOption(RemoteHostOptions.RequestServiceTimeoutInMS)); _timeout = TimeSpan.FromMilliseconds(workspace.Options.GetOption(RemoteHostOptions.RequestServiceTimeoutInMS));
_rpc = new JsonRpc(stream, stream, target: this); _rpc = new JsonRpc(new JsonRpcMessageHandler(stream, stream), target: this);
_rpc.JsonSerializer.Converters.Add(AggregateJsonConverter.Instance); _rpc.JsonSerializer.Converters.Add(AggregateJsonConverter.Instance);
// handle disconnected situation // handle disconnected situation
......
...@@ -105,6 +105,7 @@ ...@@ -105,6 +105,7 @@
<Compile Include="FindReferences\ToolTips\LazyToolTip.cs" /> <Compile Include="FindReferences\ToolTips\LazyToolTip.cs" />
<Compile Include="ProjectSystem\DeferredProjectWorkspaceService.cs" /> <Compile Include="ProjectSystem\DeferredProjectWorkspaceService.cs" />
<Compile Include="Remote\JsonRpcClient.cs" /> <Compile Include="Remote\JsonRpcClient.cs" />
<Compile Include="Remote\JsonRpcMessageHandler.cs" />
<Compile Include="Remote\JsonRpcSession.cs" /> <Compile Include="Remote\JsonRpcSession.cs" />
<Compile Include="Remote\RemoteHostClientFactory.cs" /> <Compile Include="Remote\RemoteHostClientFactory.cs" />
<Compile Include="Remote\ServiceHubRemoteHostClient.WorkspaceHost.cs" /> <Compile Include="Remote\ServiceHubRemoteHostClient.WorkspaceHost.cs" />
......
...@@ -44,6 +44,9 @@ ...@@ -44,6 +44,9 @@
</ItemGroup> </ItemGroup>
<ItemGroup /> <ItemGroup />
<ItemGroup> <ItemGroup>
<Compile Include="..\..\..\VisualStudio\Core\Next\Remote\JsonRpcMessageHandler.cs">
<Link>Shared\JsonRpcMessageHandler.cs</Link>
</Compile>
<Compile Include="..\ServiceHub\Shared\RoslynJsonConverter.cs"> <Compile Include="..\ServiceHub\Shared\RoslynJsonConverter.cs">
<Link>Shared\RoslynJsonConverter.cs</Link> <Link>Shared\RoslynJsonConverter.cs</Link>
</Compile> </Compile>
......
...@@ -60,6 +60,9 @@ ...@@ -60,6 +60,9 @@
<Compile Include="..\..\..\VisualStudio\Core\Def\Telemetry\VSTelemetryLogger.cs"> <Compile Include="..\..\..\VisualStudio\Core\Def\Telemetry\VSTelemetryLogger.cs">
<Link>Telemetry\VSTelemetryLogger.cs</Link> <Link>Telemetry\VSTelemetryLogger.cs</Link>
</Compile> </Compile>
<Compile Include="..\..\..\VisualStudio\Core\Next\Remote\JsonRpcMessageHandler.cs">
<Link>Shared\JsonRpcMessageHandler.cs</Link>
</Compile>
<Compile Include="Services\CodeAnalysisService_CodeLens.cs" /> <Compile Include="Services\CodeAnalysisService_CodeLens.cs" />
<Compile Include="Services\CodeAnalysisService_DesignerAttributes.cs" /> <Compile Include="Services\CodeAnalysisService_DesignerAttributes.cs" />
<Compile Include="Services\CodeAnalysisService_TodoComments.cs" /> <Compile Include="Services\CodeAnalysisService_TodoComments.cs" />
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Options; using Microsoft.CodeAnalysis.Options;
using Microsoft.VisualStudio.LanguageServices.Remote;
using Roslyn.Utilities; using Roslyn.Utilities;
using StreamJsonRpc; using StreamJsonRpc;
...@@ -66,7 +67,7 @@ protected ServiceHubServiceBase(IServiceProvider serviceProvider, Stream stream) ...@@ -66,7 +67,7 @@ protected ServiceHubServiceBase(IServiceProvider serviceProvider, Stream stream)
// due to this issue - https://github.com/dotnet/roslyn/issues/16900#issuecomment-277378950 // due to this issue - https://github.com/dotnet/roslyn/issues/16900#issuecomment-277378950
// all sub type must explicitly start JsonRpc once everything is // all sub type must explicitly start JsonRpc once everything is
// setup // setup
Rpc = new JsonRpc(stream, stream, this); Rpc = new JsonRpc(new JsonRpcMessageHandler(stream, stream), this);
Rpc.JsonSerializer.Converters.Add(AggregateJsonConverter.Instance); Rpc.JsonSerializer.Converters.Add(AggregateJsonConverter.Instance);
Rpc.Disconnected += OnRpcDisconnected; Rpc.Disconnected += OnRpcDisconnected;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册