diff --git a/src/Microsoft.TestPlatform.CommunicationUtilities/LengthPrefixCommunicationChannel.cs b/src/Microsoft.TestPlatform.CommunicationUtilities/LengthPrefixCommunicationChannel.cs index 293a5a683b..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; @@ -87,6 +90,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"); }