Search code examples
azureservicebus

First call to Microsoft.Azure.ServiceBus.Core.MessageSender.SendAsync times out, subsequent calls don't


I have some code written to communicate with an azure service bus. It sends messages to a queue. It's in a project targeting .net standard 2.0

When I run it from a .net core terminal app it runs fine. But, when the same code is called from a .net framework 4.7.2 project then the first attempt to send a message results in the following exception after 30 to 90 seconds:

"The remote party closed the WebSocket connection without completing the close handshake."

But any further messages will be sent without problem.

// This is using Microsoft.Azure.ServiceBus, if that makes any difference... 

MessageSender MessageSender  = new MessageSender(ConnectionString, SendQueueName;

try
{
     await MessageSender.SendAsync(new Message(Encoding.UTF8.GetBytes("Test that won't work")));
}
catch(Exception e)
{
    // Error will be caught here:
    // "The remote party closed the WebSocket connection without completing the close handshake."
}
await MessageSender.SendAsync(new Message(Encoding.UTF8.GetBytes("Test that will work")));

Does anybody know why the first call fails? And how to make it not fail? Or fail quicker? I've tried changing the OperationTimeout and RetryPolicy but they don'e seem to have any effect.


Solution

  • These first connections are via port 5671/56712, which Trend antivirus intercepts. Once these have timed out then the framework falls back to using 443, which works fine.

    We tried turning Trend off and running testing the connection and its pretty much instantaneous.