From fe0496a5c8914afb71ce3e957809f38d76baec17 Mon Sep 17 00:00:00 2001 From: Codrin Poienaru Date: Tue, 25 Jul 2023 12:17:30 +0200 Subject: [PATCH 1/2] Added delay when there are no subscribers --- .../LengthPrefixCommunicationChannel.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Microsoft.TestPlatform.CommunicationUtilities/LengthPrefixCommunicationChannel.cs b/src/Microsoft.TestPlatform.CommunicationUtilities/LengthPrefixCommunicationChannel.cs index 293a5a683b..3df924e0ef 100644 --- a/src/Microsoft.TestPlatform.CommunicationUtilities/LengthPrefixCommunicationChannel.cs +++ b/src/Microsoft.TestPlatform.CommunicationUtilities/LengthPrefixCommunicationChannel.cs @@ -87,6 +87,11 @@ public Task NotifyDataAvailable() // connection is closed. if (MessageReceived != null) { + if (MessageReceived.GetInvocationList().Length == 0) + { + Task.Delay(NoSubscriberTimeoutMs); + } + var data = _reader.ReadString(); MessageReceived.SafeInvoke(this, new MessageReceivedEventArgs { Data = data }, "LengthPrefixCommunicationChannel: MessageReceived"); } From 482d11897a1651c8c6e38411b2056098a7277fe7 Mon Sep 17 00:00:00 2001 From: Codrin Poienaru Date: Tue, 25 Jul 2023 12:43:44 +0200 Subject: [PATCH 2/2] Added timeout constant --- .../LengthPrefixCommunicationChannel.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Microsoft.TestPlatform.CommunicationUtilities/LengthPrefixCommunicationChannel.cs b/src/Microsoft.TestPlatform.CommunicationUtilities/LengthPrefixCommunicationChannel.cs index 3df924e0ef..163f09bc26 100644 --- a/src/Microsoft.TestPlatform.CommunicationUtilities/LengthPrefixCommunicationChannel.cs +++ b/src/Microsoft.TestPlatform.CommunicationUtilities/LengthPrefixCommunicationChannel.cs @@ -18,6 +18,9 @@ namespace Microsoft.VisualStudio.TestPlatform.CommunicationUtilities; /// public class LengthPrefixCommunicationChannel : ICommunicationChannel { + + private const int NoSubscriberTimeoutMs = 100; + private readonly BinaryReader _reader; private readonly BinaryWriter _writer;