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

Unsubscribe from channel after even trigger leads to crash #195

Open
radumihaiu opened this issue Nov 3, 2015 · 1 comment
Open

Unsubscribe from channel after even trigger leads to crash #195

radumihaiu opened this issue Nov 3, 2015 · 1 comment
Assignees
Labels
Milestone

Comments

@radumihaiu
Copy link

I listen for an event and when that even triggers I unsubscribe from the channel. This has about an 80% chance to produce NSGenericException*** Collection <__NSArrayM: 0x1523c7340> was mutated while being enumerated.

This is the stacktrace that bugsnag produces

Pods/libPusher/Library/PTPusherEventDispatcher.m:68:3-[PTPusherEventDispatcher dispatchEvent:]
Pods/libPusher/Library/PTPusherChannel.m:167:3-[PTPusherChannel dispatchEvent:]
Pods/libPusher/Library/PTPusher.m:381:5-[PTPusher pusherConnection:didReceiveEvent:]
Pods/libPusher/Library/PTPusherConnection.m:158:3-[PTPusherConnection webSocket:didReceiveMessage:]
Pods/SocketRocket/SocketRocket/SRWebSocket.m:753:9_30-[SRWebSocket _handleMessage:]_block_invoke

The workaround I have in order for it not to crash is to add a delay to the unsubscribing of about 1s.

@lukeredpath lukeredpath added the bug label Nov 3, 2015
@lukeredpath lukeredpath added this to the v1.6.2 milestone Nov 3, 2015
@lukeredpath lukeredpath self-assigned this Nov 3, 2015
@lukeredpath
Copy link
Contributor

Thanks for the report. I can see why unsubscribing in an event handler causes this - unsubscribing from a channel removes all bindings from the channel however the event dispatcher iterates through its bindings when it receives a matching event - when the event handler is called it will be mid-way through enumerating the bindings.

A simple solution would be to copy the bindings and enumerating over the copy, but I'll have a think about whether there is a better solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants