expo: [expo-updates][iOS] Initial call to fetchUpdateAsync() fails, succeeds on subsequent calls

Summary

We’re developing a ReactNative app using the Expo bare workflow and ReactNativeNavigation for our navigation library. Recently, we updated from Expo 39 to Expo 42. Before doing so, we never had a problem with OTA publishing with our existing code. After the update, however, we are finding that fetchUpdateAsync() fails perhaps 75% of the time or so after we have published an OTA update and restarted our app. Examining the captured error does not provide much information, but it seems the error.code is ERR_UPDATES_FETCH, the error.message is Failed to download new update, and the error.domain is EXUpdatesDatabase.

When an error occurs, we present the user with an alert box with the option to retry (see code below). Upon retrying, fetchUpdateAsync() succeeds.

Since this error does not occur on every update and since it’s possible to just re-run fetchUpdateAsync() and the fetch will succeed on the second call, it seems likely that we’re facing some sort of timeout (or region-related? Our team is based in Japan) issue. Is there an obvious fix for this that I’m missing besides checking for the returned error code and re-running fetchUpdateAsync()? Thank you.

Managed or bare workflow? If you have ios/ or android/ directories in your project, the answer is bare!

bare

What platform(s) does this occur on?

iOS

SDK Version (managed workflow only)

No response

Environment

Expo CLI 4.11.0 environment info:
    System:
      OS: macOS 11.5.1
      Shell: 5.8 - /bin/zsh
    Binaries:
      Node: 16.1.0 - /usr/local/bin/node
      Yarn: 1.22.10 - /usr/local/bin/yarn
      npm: 7.21.0 - /usr/local/bin/npm
      Watchman: 4.9.0 - /usr/local/bin/watchman
    Managers:
      CocoaPods: 1.10.2 - /usr/local/bin/pod
    SDKs:
      iOS SDK:
        Platforms: iOS 14.5, DriverKit 20.4, macOS 11.3, tvOS 14.5, watchOS 7.4
      Android SDK:
        API Levels: 29, 31
        Build Tools: 29.0.2, 31.0.0
        System Images: android-29 | Intel x86 Atom_64, android-29 | Google APIs Intel x86 Atom, android-30 | Google APIs Intel x86 Atom
    IDEs:
      Android Studio: 2020.3 AI-203.7717.56.2031.7621141
      Xcode: 12.5.1/12E507 - /usr/bin/xcodebuild
    npmPackages:
      @expo/webpack-config: ~0.14.0 => 0.14.0 
      expo: ^42.0.0 => 42.0.3 
      react: 17.0.1 => 17.0.1 
      react-dom: 17.0.1 => 17.0.1 
      react-native: 0.64.1 => 0.64.1 
      react-native-web: ~0.17.1 => 0.17.1 
    npmGlobalPackages:
      expo-cli: 4.11.0
    Expo Workflow: bare

Reproducible demo or steps to reproduce from a blank project

Obviously, a release build is required in order to test this (as expo-updating only works for release builds) so it isn’t possible to provide a snack that reproduces the issue we’re seeing, but this is the relevant code:

const checkForUpdatesAndRenderNavigation = async () => {
  try {
    const otaUpdate = await Updates.checkForUpdateAsync();

    if (otaUpdate.isAvailable) {
      await Updates.fetchUpdateAsync();
      await Updates.reloadAsync();
      return;
    }
    renderNavigationRoot();
  } catch (error) {
    showRetryAlert(error, checkForUpdatesAndRenderNavigation);
  }
};

const showRetryAlert = (error, onRetryPress) => {
  Alert.alert(
    'Something went wrong',
    `error: ${error}`,
    [
      {
        text: showRetryAlertRetryButton(),
        onPress: () => onRetryPress(),
      },
    ],
  );
};
// app.json
{
  "expo": {
    ...
    "updates": {
      "fallbackToCacheTimeout": 0,
      "checkAutomatically": "ON_ERROR_RECOVERY"
    },
    ...
  }
}

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 14
  • Comments: 23 (7 by maintainers)

Most upvoted comments

Bump

Same issue here on bare workflow. Expo v43 fetchUpdateAsync throws an error, and but it looks as though the update has been downloaded. You can reloadAsync in catch and the update will be applied. Weird.

I get the following error message:

{
  "code": "ERR_UPDATES_FETCH",
  "message": "Failed to download new update",
  "domain": "EXUpdatesData-base",
  "userInfo": {
    "NSLocalizedDescription": "Error code 19: FOREIGN KEY constraint failed (extended error code 787)",
    "nativeStackIOS": [...]
  }
}

I’m seeing this error when using EAS build on development clients…

In case it is a region issue I’ll add that we experience this in Australia. We do the same thing now with a retry button.

Hi, I had the same issue and it drove me crazy and had a hard time finally landing on that issue ! I happened to actually have some calls to Constants.manifest, though they were safe calls : e.g Constants.manifest?.expoVersion, but removing them finally did the trick

@esamelson not a reproducable repo, but here is the output of nativeStackIOS for us. Hopefully this helps.

Similar to @Maker-Mark, this is on an EAS Production OTA update.

{
  "userInfo": {
    "NSLocalizedDescription": "Error code 19: FOREIGN KEY constraint failed (extended error code 787)"
  },
  "code": "ERR_UPDATES_FETCH",
  "level": "error",
  "domain": "EXUpdatesDatabase",
  "host": "iPhone 11 Pro Max",
  "nativeStackIOS": [
    "0   app-name                            0x000000010238aac8 _ZN8facebook5react11JSIExecutor21defaultTimeoutInvokerERKNSt3__18functionIFvvEEENS3_IFNS2_12basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEEvEEE + 687800",
    "1   app-name                            0x000000010235c148 _ZN8facebook5react11JSIExecutor21defaultTimeoutInvokerERKNSt3__18functionIFvvEEENS3_IFNS2_12basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEEvEEE + 496952",
    "2   app-name                            0x00000001021c5ffc app-name + 1335292",
    "3   libdispatch.dylib                   0x00000001802a5924 BD02A625-8475-3FD6-8DC3-8AED25D1573B + 10532",
    "4   libdispatch.dylib                   0x00000001802a7670 BD02A625-8475-3FD6-8DC3-8AED25D1573B + 18032",
    "5   libdispatch.dylib                   0x00000001802aedf4 BD02A625-8475-3FD6-8DC3-8AED25D1573B + 48628",
    "6   libdispatch.dylib                   0x00000001802af968 BD02A625-8475-3FD6-8DC3-8AED25D1573B + 51560",
    "7   libdispatch.dylib                   0x00000001802ba1b8 BD02A625-8475-3FD6-8DC3-8AED25D1573B + 94648",
    "8   libsystem_pthread.dylib             0x00000001f10c30f4 _pthread_wqthread + 288",
    "9   libsystem_pthread.dylib             0x00000001f10c2e94 start_wqthread + 8"
  ]
}

EDIT: This was magically fixed after removing all calls to Constants.manifest. I’m not sure if this is related, but updates are working for now 🙌

Hi everyone, I attempted to make a reproduction of this issue but was unable to. Here’s the repo: https://github.com/jonsamp/test-3-9-fetch-updates/tree/main

Inside the README.md are the steps I took and a video example of loading an update on app refocus. If anyone can modify this repo in a way to reproduce the bug, then we can get to the bottom of this issue.

Seeing this randomly as well, located in the USA. We’re fetching the updates before presenting an option to apply them, but seeing the failures logged to Sentry.