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

[ios] RCTBundleURLProvider isPackagerRunning stalls for wifi-disabled device #10187

Closed
aleclarson opened this issue Sep 30, 2016 · 8 comments
Closed
Labels
Platform: iOS iOS applications. Resolution: Locked This issue was locked by the bot.

Comments

@aleclarson
Copy link
Contributor

aleclarson commented Sep 30, 2016

Specifically this line is blocking the thread when using a device (with WIFI unknowingly disabled).

Might want to use a semaphore and RCTLogError.

Otherwise, the user is left confused about the stalled thread.

@lacker
Copy link
Contributor

lacker commented Feb 7, 2017

What's the problematic result here - when you run on a device with no internet connection it silently fails and the ideal would be to log a message saying "there's no internet"? If you have a specific fix in mind with the semaphore then it would be really cool to submit a PR fixing it....

@shergin shergin added the Platform: iOS iOS applications. label Mar 16, 2017
@v-ahuja
Copy link

v-ahuja commented May 27, 2017

Both https://stackoverflow.com/questions/44102199/react-native-dev-mode-app-doesnt-fallback-to-offline-bundle-on-physical-device and https://stackoverflow.com/questions/43616804/react-native-ios-app-crashes-when-run-outside-of-xcode-with-failed-to-scene-crea are caused by this.

My expectation is that it should fall back to the offline bundle. Really, with a dev build, I can't use the app in offline mode because of this issue.

@v-ahuja
Copy link

v-ahuja commented May 28, 2017

I have a temporary workaround and am putting it here for documentation purposes in case someone with a better knowledge of objective-c (i have none), url resolution and xip.io can put in the proper change (more on that later). Please note that this is a very fragile solution. However, I'm still posting this here because as I said earlier, if you'd like to load the offline bundle when you aren't connected to your app, the current state of affairs makes it almost impossible; apple will kill your app during loading time if the synchronous http call to resolve whether a packager is running takes longer than 19 seconds (and this is often the case for me).

Disclaimers:
(a) Try this at your own risk.
(b) You have to make sure you turn off 'Debug JS Remotely' in the inspector, when you're not on wifi, otherwise, react tries to fallback to hitting localhost.

In RCTBundleURLProvider.m (isPackagerRunning) replace the commented section with what's below:

// NSURLRequest *request = [NSURLRequest requestWithURL:url];
  // NSURLResponse *response;
  // NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:NULL];
  // NSString *status = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
  // return [status isEqualToString:@"packager-status:running"];

  NSURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:5];
  NSHTTPURLResponse *response = nil;
  NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:NULL];
  if (response == nil) {
      // timed out or failed
      NSLog(@"sync request timed out.");
      return false;
  } else {
      // all good
      NSString *status = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
      return [status isEqualToString:@"packager-status:running"];
  }
  return false;

This will cause URL resolution to time-out in 5 seconds and therefore fallback to the offline bundle.
HOWEVER, if this doesn't work with xip.io (in my case, it seemingly didn't), modify the script react-native-xcode.sh by replacing $IP.xip.io with $IP

@v-ahuja
Copy link

v-ahuja commented May 28, 2017

Proper fix discussion:

I'm not sure if this possible, but this synchronous call to figure out if the packager is running -
(a) shouldn't be made on the main thread, since ios will crash you if the main thread takes longer than 19s (approx) to end.
(b) shouldn't be synchronous at all, but instead should be async.

Also, I'd like to add that I've noticed that switching back and forth between WiFI and cellular doesn't work well and is quite fragile. React falls back to localhost often, even when the packager is running. The fact that it's inconsistent is worrisome.

@v-ahuja
Copy link

v-ahuja commented Jun 4, 2017

ping

@MarkRich
Copy link

ping as well. also having this problem.

@v-ahuja
Copy link

v-ahuja commented Jun 16, 2017

Can we get a 'needs help' label on this? would be cool if someone with objective-c knowledge can help out on this.

@hramos hramos added the Icebox label Aug 24, 2017
@hramos
Copy link
Contributor

hramos commented Aug 24, 2017

Hi there! This issue is being closed because it has been inactive for a while. Maybe the issue has been fixed in a recent release, or perhaps it is not affecting a lot of people. Either way, we're automatically closing issues after a period of inactivity. Please do not take it personally!

If you think this issue should definitely remain open, please let us know. The following information is helpful when it comes to determining if the issue should be re-opened:

  • Does the issue still reproduce on the latest release candidate? Post a comment with the version you tested.
  • If so, is there any information missing from the bug report? Post a comment with all the information required by the issue template.
  • Is there a pull request that addresses this issue? Post a comment with the PR number so we can follow up.

If you would like to work on a patch to fix the issue, contributions are very welcome! Read through the contribution guide, and feel free to hop into #react-native if you need help planning your contribution.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Platform: iOS iOS applications. Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests

7 participants