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

Amqp connections are not getting disposed #1771

Merged
merged 3 commits into from
Feb 4, 2021
Merged

Amqp connections are not getting disposed #1771

merged 3 commits into from
Feb 4, 2021

Conversation

jamdavi
Copy link
Member

@jamdavi jamdavi commented Feb 4, 2021

Fixes #1770 by reverting regression introduced in this change.

@@ -548,17 +548,12 @@ protected override void Dispose(bool disposing)
{
base.Dispose(disposing);

if (_disposed)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this a problem?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1. We seem to set _disposed to true only after removing the amqp unit, so it shouldn't cause leaks, right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@abhipsaMisra - Are you not OOF :D Take rest!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_disposed is a protected field from the base class. That's what's throwing us all off

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when we call base.Dispose(), the _disposed is getting set to false, then we bail out prematurely.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved the dispose to below the if statement to match the pattern of the other handlers.

Logging.Info(this, $"{nameof(disposing)}");

if (disposing)
{
_closed = true;
AmqpUnitManager.GetInstance().RemoveAmqpUnit(_amqpUnit);
AmqpUnitManager.GetInstance()?.RemoveAmqpUnit(_amqpUnit);
_disposed = true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we never use the _disposed field, we should just remove it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nvm. Talked to James offline and he explained it to me.
Based on our conversation, we can still keep the if(_disposed) check if we move it above the base.Dispose() call.

@jamdavi
Copy link
Member Author

jamdavi commented Feb 4, 2021

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@vinagesh
Copy link
Member

vinagesh commented Feb 4, 2021

Can we add anything to catch this before customers? E2E test? Not this PR but after this.

@jamdavi
Copy link
Member Author

jamdavi commented Feb 4, 2021

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@jamdavi
Copy link
Member Author

jamdavi commented Feb 4, 2021

Can we add anything to catch this before customers? E2E test? Not this PR but after this.

We could add some monitoring to long haul. To do this in an integration test we'd need to mark the _amqpUnit member as internal to check to see if it's still part of the AmqpUnitManager and if it's disposed.

I'll put a PR out for that to see what everyone thinks.

@vinagesh
Copy link
Member

vinagesh commented Feb 4, 2021

Can we add anything to catch this before customers? E2E test? Not this PR but after this.

We could add some monitoring to long haul. To do this in an integration test we'd need to mark the _amqpUnit member as internal to check to see if it's still part of the AmqpUnitManager and if it's disposed.

I'll put a PR out for that to see what everyone thinks.

Awesome! We can see how the test looks but we should definitely add some monitoring to long haul as we did not catch it when we released this time and this seems to be something that we should cover as a basic functionality.

Copy link
Member

@abhipsaMisra abhipsaMisra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everyone is on board! 😄

@jamdavi jamdavi merged commit fb60816 into master Feb 4, 2021
@jamdavi jamdavi deleted the jamdav/issue1770 branch February 4, 2021 23:40
timstewartm pushed a commit to timstewartm/azure-iot-sdk-csharp that referenced this pull request May 30, 2024
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

Successfully merging this pull request may close these issues.

DeviceClient.Dispose() does not close socket connections
6 participants