Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
RusuIonut21 opened this issue Jun 6, 2024 · 2 comments

Comments

@RusuIonut21
Copy link
Contributor

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.

RusuIonut21 added a commit to RusuIonut21/amqpnetlite that referenced this issue Jun 6, 2024
Execute link.Send() in a try-catch block. If an error occurs, no action is needed because the client already received an exception.
xinchen10 pushed a commit that referenced this issue Jun 6, 2024
Execute link.Send() in a try-catch block. If an error occurs, no action is needed because the client already received an exception.
@xinchen10
Copy link
Member

Thank you for reporting and fixing the issue.

@RusuIonut21
Copy link
Contributor Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants