Skip to content

Conversation

@imurashka
Copy link
Contributor

Problem

During Dispose() method, the composite enumerates its internal list. If a client adds a disposable at that time, the list is mutated and we get:
InvalidOperationException: Collection was modified; enumeration operation may not execute.

Root cause

Add/AddRange methods continued to push into the internal list after disposal had begun.

Fix

If the composite is disposed, Add/AddRange dispose the incoming item(s) immediately.

Notes

  • API unchanged; callers that add after disposal simply have their disposables disposed.
  • Exception aggregation slightly improved: single exception is rethrown as-is.

@imurashka imurashka closed this Nov 4, 2025
@imurashka imurashka reopened this Nov 4, 2025
Copy link
Collaborator

@eldarmguseynov eldarmguseynov left a comment

Choose a reason for hiding this comment

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

Thank you, good fix. Can you please add unit tests? Also, in which case did you think it might happen? Adding disposable in controller's dispose?

@imurashka
Copy link
Contributor Author

@eldarmguseynov, hey! I've added unit tests to ControllerCompositeDisposable.
Regarding your question "Also, in which case did you think it might happen? Adding disposable in controller's dispose?" - yes I faced with this issue when some controller added disposable during its Dispose.

@perepechenko perepechenko self-requested a review November 17, 2025 16:21
@perepechenko perepechenko merged commit 8b648de into PlaytikaOSS:main Nov 17, 2025
1 check passed
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