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

ObjectDisposedException when connection is closed from the server #1760

Closed
lukebakken opened this issue Jan 7, 2025 · 2 comments · Fixed by #1772
Closed

ObjectDisposedException when connection is closed from the server #1760

lukebakken opened this issue Jan 7, 2025 · 2 comments · Fixed by #1772
Assignees
Labels
Milestone

Comments

@lukebakken
Copy link
Contributor

lukebakken commented Jan 7, 2025

Describe the bug

Logging FirstChanceExceptions shows some strange ObjectDisposedException:

https://github.com/rabbitmq/rabbitmq-dotnet-client/blob/v7.0.0/projects/RabbitMQ.Client/Impl/Connection.Heartbeat.cs#L164 accessing .Token here can result in an ObjectDisposedException. That is catched, but the comment states that its for the timer

The SetSessionClosingAsync uses a _closingSemaphore that can already be disposed. It seems this isn't gracefully handled in the stacktrace.

https://github.com/rabbitmq/rabbitmq-dotnet-client/blob/v7.0.0/projects/RabbitMQ.Client/Impl/MainSession.cs

I'm not sure if this is causing issues but looking at the code it might be needed that these code paths all need to have exception handling to prevent code not to terminate if these ObjectDisposedExceptions are to be expected.

Reproduction steps

  1. Use MassTransit.RabbitMQ 8.3.4
  2. Log FirstChanceException
  3. Create a consumer and connect to the broker
  4. Close the connections on the broker
  5. Observe the consumer trying to reconnect

Do this a couple of times and you'll see the related exception

Expected behavior

gracefully handle ObjectDisposedException on all code paths for closed connections

Additional context

Originally reported by @ramonsmits here: #1749

@lukebakken
Copy link
Contributor Author

@ramonsmits I have created the following branch with a test project, GH-1749, that repeatedly closes connections:

https://github.com/rabbitmq/rabbitmq-dotnet-client/tree/rabbitmq-dotnet-client-1760

I've been running that project for a while now, and don't see any first-chance ObjectDisposedExceptions logged.

Would you mind testing in your environment, using this version?

https://www.nuget.org/packages/RabbitMQ.Client/7.1.0-alpha.0

Thank you!

@lukebakken
Copy link
Contributor Author

@ramonsmits I am closing this issue as I did not hear back from you, nor could I reproduce it. Please follow up if you have anything else to add.

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

Successfully merging a pull request may close this issue.

1 participant