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

MOB-22620: Fix concurrent modification exception during session termination #147

Open
wants to merge 2 commits into
base: dev-v3.x
Choose a base branch
from

Conversation

prudrabhat
Copy link
Contributor

@prudrabhat prudrabhat commented Jan 21, 2025

Description

Problem

notifyTerminationAndRemoveStatusListeners() iterates over all the connection status listeners to notify disconnection and un-registers them. Since the de-registration process involves removing the listeners from the set, iterating over the same list for removal leads to ConcurrentModificationException and not all listeners are notified of the error. This results in the connecting icon spinning forever.
This situation only occurs for terminal errors/ non retryable errors so it does not affect the normal workflow.

Solution

Iterate for de-registration over a copy of the listeners to prevent the exception and propagate the error.

Related Issue

MOB-22620

Motivation and Context

notifyTerminationAndRemoveStatusListeners() iterates over all the connection status listeners to notify disconnection and un-registers them. Since the de-registration process involves removing the listeners from the set, iterating over the same list for removal leads to ConcurrentModificationException and not all listeners are notified of the error. This results in the connecting icon spinning forever.
As a solution, iterate for de-registration over a copy of the listeners to prevent the exception and propagate the error.

How Has This Been Tested?

  • Manual tests
  • Existing unit tests

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • I have signed the Adobe Open Source CLA.
  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

Problem:

`notifyTerminationAndRemoveStatusListeners()` iterates over all the connection
status listeners to notify disconnection and un-registers them. Since the
de-registration process involves removing the listeners from the set, iterating over
the same list for removal leads to ConcurrentModificationException and not all listeners
are notified of the error. This results in the connecting icon spinning forever.

Solution:

Iterate for  de-registration over a copy of the listeners to prevent the exception
and propogate the error.

// Unregister all the listeners. Operate on a copy of the listeners as
// unregisterStatusListener modifies the listeners set.
final Set<AssuranceSessionStatusListener> listenersCopy =
Copy link
Contributor

@praveek praveek Jan 21, 2025

Choose a reason for hiding this comment

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

How about sessionStatusListeners.clear() ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes! Clearing here is better. Will patch.

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.

3 participants