-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Issue #156: Prevents crash in handleEvent method #169
Conversation
Hi @jleandroperez, so have the crash reports stopped after applying this? Thanks! |
@marianoabdala So far i have not received any further crash reports. I'll keep you posted (if it happens ever again!). |
Conflicts: SocketRocket/SRWebSocket.m Up to PR facebookincubator#169 merged
Conflicts: SocketRocket/SRWebSocket.m
Conflicts: SocketRocket/SRWebSocket.m
Any updates on getting this merged? |
I am receiving crash reports just like these in my app. Is there any possibility of getting this merged? |
Same here, why is it not merged ? |
NSStream doesn't retain its delegate. If the code isn't retaining the delegate elsewhere, it will become a zombie. It is not safe to allow the delegate to go away until you completely tear down the stream. So if I'm reading the description of the "workaround" correctly, it isn't a workaround so much as a bug fix. |
@@ -0,0 +1,41 @@ | |||
<?xml version="1.0" encoding="UTF-8"?> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file looks like it should be in your .gitignore. Please remove.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry about that, removing right away!
Sorry for the long delay. I'd rather avoid using Thanks, |
On the contrary @mikelikespie, thanks for the review (+ for opensourcing this project, we use it quite a lot!). I'm afraid that simply replacing the Perhaps we could switch to Thank you sir! |
- (void)safeHandleEvent:(NSStreamEvent)eventCode stream:(NSStream *)aStream | ||
{ | ||
__strong typeof(self) strongSelf = self; | ||
((void)strongSelf); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Self is always strong. Don't need this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right Mike. Pre-arc school says 'that's not accurate', but post arc school says otherwise. Thank you, updating =)
@jleandroperez I feel like you could do most of it by dispatching on the _workQueue (at least making sure you only schedule the cleanup once). I think you can call |
Hello there @mikelikespie! I'm afraid that moving the cleanup code to the |
@jleandroperez Can you elaborate on why |
Ping @jleandroperez :) |
I have described an alternative solution to this here: #156 (comment). I'd love to hear any thoughts on it 😃 |
Hello @mikelikespie and @dfed, Apologies about the delay gentleman!. The reason why the cleanup sequence needs to be called on the same thread used by NSStream's delegate property is not weak, but assign. Invalidating that pointer from elsewhere can explain the race condition we've been seeing (and the associated crashes). That's the reason why, i'm afraid, moving the cleanup call back to the I'll merge the conflicts shortly (and will address the And again, thank you both for sharing this project! |
@mikelikespie ready for another round sir!. All comments have been addressed. In the aims of making the reviewer's life happier, the (If) this PR is approved, i'd be happy to remove that tab (just temporarily there). @jtreanor i'm not a big fan of Singletons, but i'll definitely take a look at your solution. Sounds less invasive, thanks for sharing! |
Are you planning merge it? This request potentially can fix very popular crash. |
Hey folks! Our turn to be slow. We've got a merge/reviewfest this Thursday and we'll take a look then. |
Thank you @dfed, much appreciated! |
This looks reasonable to me. Thanks for the poke folks. Merging! |
Issue #156: Prevents crash in handleEvent method
Pure awesomeness, thanks a lot @dfed!! |
Issue facebookincubator#156: Prevents crash in handleEvent method
We've been seeing crashes with the stack trace posted below. Our app is crashing during a block_copy operation, performed inside the method
[SRWebSocket stream:handleEvent:]
.Although i've been unable to directly reproduce this, i've added a couple safety measures that would prevent this from happening.
Suspected scenario:
stream:handleEvent:
in a BG thread.stream:handleEvent:
calls the dispatch_async routine, reference to self is no longer valid.Workaround:
stream:handleEvent:
method: part of the code was moved to a second method, with a self-strong reference, stored in the stack.Any feedback will be very welcome. Thanks in advance, and congratulations on building this awesome project!
Crash Stack Trace: