Skip to content

Conversation

@RangerRick
Copy link

This PR changes processing event handlers so it iterates the array of listeners the old-fashioned way -- by index -- rather than using in handlers, in order to avoid "mutated while being enumerated" errors.

I ran into this when using the code with my Capacitor plugin because I was adding and removing event listeners in different bits of my client code somewhat regularly.

Copy link

@gwhelanLD gwhelanLD left a comment

Choose a reason for hiding this comment

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

Hi @RangerRick,

Thanks for the PR. Looks like your change should fix the issue. Normally index iteration would also be unsafe, but it should be okay as we never remove elements from the array of listeners.

As a note we're deprecating this library, as we've moved our iOS client SDK to to use https://github.com/launchdarkly/swift-eventsource instead. We'll be accepting bug fixes until July 2021, at which point we'll be dropping support.

I'll merge this and we'll have a patch release out soon.

Thanks again,
@gwhelanLD

@gwhelanLD gwhelanLD merged commit 31929c6 into launchdarkly:master Sep 8, 2020
@gwhelanLD gwhelanLD mentioned this pull request Sep 11, 2020
gwhelanLD added a commit that referenced this pull request Sep 11, 2020
## [4.1.1] - 2020-09-11

### Fixed
- Thanks to @RangerRick fo PR [#32](#32), fixing "NSArray was mutated while being enumerated" exceptions when adding listeners while events are being dispatched.
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.

2 participants