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

Fix: edgeAgent creates rogue ModuleClients in case of error #5332

Merged
merged 5 commits into from
Aug 11, 2021

Conversation

vipeller
Copy link
Contributor

@vipeller vipeller commented Aug 5, 2021

causing multiple ModuleClients trying to connect with same identity.

When edgeAgent creates a new instance of module client, it sets up subscriptions. If that failed (e.g in case of network problem), then the newly created ModuleClient was left there without referencing it and nothing closed it afterwards. Later edgeAgent needed to create a new module client again (as the previous attempt failed). Thus at least two active ModuleClient was created with the same connection string, both trying to connect iothub. When this happened, they started to fight over the connection - iothub always disconnected the previously connected ModuleClient.
Because edgeAgent pulls a twin at every connection, the connection fight mentioned above caused pulling several twins in every second.

nyanzebra
nyanzebra previously approved these changes Aug 5, 2021
// swallowing intentionally
}

throw;
Copy link
Contributor

Choose a reason for hiding this comment

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

Where would this get caught/handled?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the main idea of the rethrow was to not change the existing error handling, but

  • this is called from an OnClosed() event handler, and it catches and swallows the exception
  • it is called by 'GetTwinFromIotHub' which catches it and either retries or just swallows the exception (retries once)
  • called from the ModuleClient ctor - there the idea I suppose that the module client subscribes to events (method handler and desired properties) plus when the connection gets closed, it reopens. I think this latter logic might be broken as I see, because started offline, the method will throw an exception and I don't see how it would automatically create a new connection anytime soon (it will when some periodic operation, like twin pull requests a new connection) - but again, with this change the logic stays the same.

added a ticket for this last question: (10555951)

Copy link
Contributor

@varunpuranik varunpuranik left a comment

Choose a reason for hiding this comment

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

Change looks good. Can we add a test for it?

@kodiakhq kodiakhq bot merged commit e3892eb into Azure:master Aug 11, 2021
vipeller added a commit to vipeller/iotedge that referenced this pull request Aug 11, 2021
vipeller added a commit to vipeller/iotedge that referenced this pull request Aug 11, 2021
kodiakhq bot pushed a commit that referenced this pull request Sep 7, 2021
…ror (#5332) (#5359)

cherry pick of the twin pull peak problem (#5332)
kodiakhq bot pushed a commit that referenced this pull request Sep 20, 2021
…ror (#5332) (#5360)

cherry pick of the twin pull peak problem (#5332)
damonbarry pushed a commit to damonbarry/iotedge that referenced this pull request Apr 15, 2022
causing multiple ModuleClients trying to connect with same identity.

When edgeAgent creates a new instance of module client, it sets up subscriptions. If that failed (e.g in case of network problem), then the newly created ModuleClient was left there without referencing it and nothing closed it afterwards. Later edgeAgent needed to create a new module client again (as the previous attempt failed). Thus at least two active ModuleClient was created with the same connection string, both trying to connect iothub. When this happened, they started to fight over the connection - iothub always disconnected the previously connected ModuleClient.
Because edgeAgent pulls a twin at every connection, the connection fight mentioned above caused pulling several twins in every second.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants