react-native-macos/Libraries/WebSocket
Lukas Weber 0d4b0e9417 Fixes RCTReconnectingWebSocket connecting in infinite loop when stopped before it connects (#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: https://github.com/facebook/react-native/pull/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
2020-02-11 10:54:39 -08:00
..
__mocks__ Update copyright headers to yearless format 2018-09-11 15:33:07 -07:00
__tests__ Migrate "Libraries" from Haste to standard path-based requires (sans vendor & renderers) (#24749) 2019-05-08 08:48:59 -07:00
NativeWebSocketModule.js Make RCTWebSocketModule TurboModule-compatible 2019-11-08 14:14:46 -08:00
RCTReconnectingWebSocket.h Tidy up license headers [2/n] 2019-10-16 10:06:34 -07:00
RCTReconnectingWebSocket.m Fixes RCTReconnectingWebSocket connecting in infinite loop when stopped before it connects (#26864) 2020-02-11 10:54:39 -08:00
RCTSRWebSocket.h Backed out changeset 183744d2415b 2016-03-15 11:49:28 -07:00
RCTSRWebSocket.m Enabling RCTWebSocket on UIKitForMac (macOS Catalyst) (#27469) 2019-12-17 16:52:29 -08:00
WebSocket.js Clear some lint warnings (#27893) 2020-01-29 04:36:28 -08:00
WebSocketEvent.js Update copyright headers to yearless format 2018-09-11 15:33:07 -07:00
WebSocketInterceptor.js Add spec for WebSocketModule (#24893) 2019-05-30 14:29:42 -07:00