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

Fixes RCTReconnectingWebSocket connecting in infinite loop when stopped before it connects #26864

Closed
wants to merge 1 commit into from

Conversation

isnotgood
Copy link

Summary

When [RCTReconnectingWebSocket stop] is called and [RCTReconnectingWebSocket reconnect] is scheduled afterwards (i.e. connection didn't happen before [RCTReconnectingWebSocket stop] being invoked), it will keep reconnecting forever.

Also fixes retain loop in block within [RCTReconnectingWebSocket reconnect]. When RCTReconnectingWebSocket is stopped and reference to it set to nil, block in reconnect will still keep self alive and reconnecting forever.

I found this edge case when I tried to stop RCTPackagerConnection after some time, so it doesn't spam with [] nw_socket_handle_socket_event [C34585.1:1] Socket SO_ERROR [61: Connection refused] when we don' have Metro running (we have brownfield app, so iOS devs don't need Metro running most of the time).

Changelog

[iOS] [Fixed] - RCTReconnectingWebSocket is reconnecting infinitely when stopped before getting connected

Test Plan

  • Put breakpoint into [RCTReconnectingWebSocket reconnect]
  • Start sample RN app without having Metro running
  • Into AppDelegate add something like
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ 
   [RCTPackagerConnection.sharedPackagerConnection stop]
});
  • After the previous block is dispatched reconnect should not be invoked anymore

@facebook-github-bot
Copy link
Contributor

Hi isnotgood! Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file.In order for us to review and merge your code, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

If you have received this in error or have any questions, please contact us at cla@fb.com. Thanks!

@react-native-bot react-native-bot added Bug Platform: iOS iOS applications. labels Oct 15, 2019
@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Oct 15, 2019
@facebook-github-bot
Copy link
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

@isnotgood isnotgood changed the title Fixes RCTReconnectingWebSocket infinite reconnecting edge case Fixes RCTReconnectingWebSocket connecting in infinite loop when stopped before is connected Oct 24, 2019
…ped.

When [RCTReconnectingWebSocket stop] is invoked reconnect will restart
connection if it wasn't previously connected. Also fixes retain loop in
reconnect which causes RCTReconnectingWebSocket to live forever :)
@isnotgood isnotgood changed the title Fixes RCTReconnectingWebSocket connecting in infinite loop when stopped before is connected Fixes RCTReconnectingWebSocket connecting in infinite loop when stopped before it connects Jan 23, 2020
Copy link
Member

@rickhanlonii rickhanlonii left a comment

Choose a reason for hiding this comment

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

Sorry I missed this, this LGTM!

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

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

@rickhanlonii has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@react-native-bot
Copy link
Collaborator

This pull request was successfully merged by @isnotgood in 0d4b0e9.

When will my fix make it into a release? | Upcoming Releases

@react-native-bot react-native-bot added the Merged This PR has been merged. label Feb 11, 2020
osdnk pushed a commit to osdnk/react-native that referenced this pull request Mar 9, 2020
…ed before it connects (facebook#26864)

Summary:
When `[RCTReconnectingWebSocket stop]` is called and `[RCTReconnectingWebSocket  reconnect]` is scheduled afterwards (i.e. connection didn't happen before `[RCTReconnectingWebSocket stop]` being invoked), it will keep reconnecting forever.

Also fixes retain loop in block within `[RCTReconnectingWebSocket  reconnect]`. When RCTReconnectingWebSocket is stopped and reference to it set to nil, block in reconnect will still keep self alive and reconnecting forever.

I found this edge case when I tried to stop RCTPackagerConnection after some time, so it doesn't spam with `[] nw_socket_handle_socket_event [C34585.1:1] Socket SO_ERROR [61: Connection refused]` when we don' have Metro running (we have brownfield app, so iOS devs don't need Metro running most of the time).

## Changelog
[iOS] [Fixed] -  RCTReconnectingWebSocket is reconnecting infinitely when stopped before getting connected
Pull Request resolved: facebook#26864

Test Plan:
- Put breakpoint into `[RCTReconnectingWebSocket  reconnect]`
- Start sample RN app **without having Metro running**
- Into AppDelegate add something like
```objc
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
   [RCTPackagerConnection.sharedPackagerConnection stop]
});
```
- After the previous block is dispatched reconnect should not be invoked anymore

Reviewed By: motiz88

Differential Revision: D19767742

Pulled By: rickhanlonii

fbshipit-source-id: dabb2369b06217b961e9d2611257c106d350f70c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged. Platform: iOS iOS applications.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants