From c0e04460f546dfef2623bff367eb8db8fd75fa34 Mon Sep 17 00:00:00 2001 From: Radek Pietruszewski Date: Mon, 20 Sep 2021 13:03:37 -0700 Subject: [PATCH] Time out packager liveness check after 10s (#31367) Summary: `isPackagerRunning` check on iOS makes a http request to packager's /status endpoint to check if it's alive... The problem is if the packager can't be reached, but doesn't error out immediately. This can happen, for example, if running the app on device, and host computer's firewall doesn't allow a :8081 connection. In that case, the request will never succeed or fail until default timeout of 60s. It makes debugging the underlying issue quite unbearable. It's hard for me to imagine a legitimate packager connection that wouldn't respond in less than a second, so I propose a conservative timeout of 10s ## Changelog [iOS] [Fixed] - Don't hang app for 60s if packager can't be reached Pull Request resolved: https://github.com/facebook/react-native/pull/31367 Test Plan: Checked my app in dev mode to see if packager connects properly. Reviewed By: sammy-SC Differential Revision: D30912047 Pulled By: charlesbdudley fbshipit-source-id: 110743dc45b9cc7d30e49f79ce3b0d5986f7aebd --- React/Base/RCTBundleURLProvider.mm | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/React/Base/RCTBundleURLProvider.mm b/React/Base/RCTBundleURLProvider.mm index eea970452f7a6d..cf2b2d2dca19ae 100644 --- a/React/Base/RCTBundleURLProvider.mm +++ b/React/Base/RCTBundleURLProvider.mm @@ -90,7 +90,9 @@ + (BOOL)isPackagerRunning:(NSString *)hostPort scheme:(NSString *)scheme NSURL *url = [serverRootWithHostPort(hostPort, scheme) URLByAppendingPathComponent:@"status"]; NSURLSession *session = [NSURLSession sharedSession]; - NSURLRequest *request = [NSURLRequest requestWithURL:url]; + NSURLRequest *request = [NSURLRequest requestWithURL:url + cachePolicy:NSURLRequestUseProtocolCachePolicy + timeoutInterval:10]; __block NSURLResponse *response; __block NSData *data;