Skip to content

Commit

Permalink
(upstream) Prevent SocketRocket killing the connection before notifyi…
Browse files Browse the repository at this point in the history
…ng of final messages

Summary: wrap NSStreamEventEndEncountered in dispatch_async _workQueue per upstream:
facebookincubator/SocketRocket#294

CLA completed
Closes #3493

Reviewed By: svcscm

Differential Revision: D2554892

Pulled By: javache

fb-gh-sync-id: 347a37eb95b20b7e92b985b6908e15462672e83c
  • Loading branch information
joenoon authored and facebook-github-bot-4 committed Oct 19, 2015
1 parent 9dc036d commit 607527c
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions Libraries/WebSocket/RCTSRWebSocket.m
Original file line number Diff line number Diff line change
Expand Up @@ -1381,20 +1381,22 @@ - (void)stream:(NSStream *)aStream handleEvent:(NSStreamEvent)eventCode;
if (aStream.streamError) {
[self _failWithError:aStream.streamError];
} else {
if (self.readyState != RCTSR_CLOSED) {
self.readyState = RCTSR_CLOSED;
_selfRetain = nil;
}
dispatch_async(_workQueue, ^{
if (self.readyState != RCTSR_CLOSED) {
self.readyState = RCTSR_CLOSED;
_selfRetain = nil;
}

if (!_sentClose && !_failed) {
_sentClose = YES;
// If we get closed in this state it's probably not clean because we should be sending this when we send messages
[self _performDelegateBlock:^{
if ([self.delegate respondsToSelector:@selector(webSocket:didCloseWithCode:reason:wasClean:)]) {
[self.delegate webSocket:self didCloseWithCode:RCTSRStatusCodeGoingAway reason:@"Stream end encountered" wasClean:NO];
}
}];
}
if (!_sentClose && !_failed) {
_sentClose = YES;
// If we get closed in this state it's probably not clean because we should be sending this when we send messages
[self _performDelegateBlock:^{
if ([self.delegate respondsToSelector:@selector(webSocket:didCloseWithCode:reason:wasClean:)]) {
[self.delegate webSocket:self didCloseWithCode:RCTSRStatusCodeGoingAway reason:@"Stream end encountered" wasClean:NO];
}
}];
}
});
}

break;
Expand Down

0 comments on commit 607527c

Please sign in to comment.