Azure / amqpnetlite

AMQP 1.0 .NET Library
Apache License 2.0
402 stars 145 forks source link

Calling SendAsync while the connection is closing/closed results in an UnobservedTaskException #584

Closed RusuIonut21 closed 5 months ago

RusuIonut21 commented 5 months ago

I am using the library to send/receive messages to a message broker (ActiveMQ Artemis). Also I have a handler for TaskScheduler.UnobservedTaskException to close the process if any exception occurs.

If I send a message while the connection with the message broker is down, I receive an exception (as expected). The problem is that I also get an UnobservedTaskException containing a TimeoutException because of it.

It seems that the problem is in SendTask class:

public SendTask(SenderLink link, Message message, DeliveryState state, TimeSpan timeout)
{
    this.timer = new Timer(onTimer, this, (int)timeout.TotalMilliseconds, -1);
    link.Send(message, state, onOutcome, this);
}

The call link.Send can fail, but if that happens, the timer is not disposed and the timeout exception is thrown in an unobserved task. This king of behavior also happens when the link.Send fails, but onOutcome callback is still fired.

xinchen10 commented 5 months ago

Thank you for reporting and fixing the issue.

RusuIonut21 commented 5 months ago

@xinchen10 When can I expect a new release with this fix?