Gitlab CI publish fails on limit of file watchers

I’m trying to set up a pipeline in Gitlab to test and publish to Expo. Testing works fine; but the “expo publish” always fails in the iOS bundle build with this message:

[17:48:52] Unable to find an existing Expo CLI instance for this directory, starting a new one…
[17:48:54] Starting Metro Bundler on port 19001.
[17:48:55] Publishing to channel ‘default’…
[17:48:56] Building iOS bundle
[17:49:07] internal/fs/watchers.js:173
[17:49:07] throw error;
[17:49:07] ^
[17:49:07]
[17:49:07] Error: ENOSPC: System limit for number of file watchers reached…

My .gitlab-ci.yml file looks like this:

image: node:alpine
cache:
  key: ${CI_COMMIT_REF_SLUG}
  paths:
    - node_modules/
    - .yarn
stages:
  - test
  - deploy
before_script:
  - yarn config set cache-folder .yarn
  - yarn install --frozen-lockfile
jest-tests:
  stage: test
  script:
    - yarn run jest --ci
expo-deployments:
  stage: deploy
  script:
    - apk add --no-cache bash
    - yarn run expo login -u $EXPO_USERNAME -p $EXPO_PASSWORD
    - yarn run expo publish --non-interactive

FYI, the error persisted even after I added “echo ‘fs.inotify.max_user_watches=524288’” to the “script” section of the CI config file

For anyone who experiences the same error, the problem was solved by adding the following line to .gitlab-ci.yml after “- ap ask --no-cache bash”:

echo fs.inotify.max_user_watches=524288 | tee -a /etc/sysctl.conf && sysctl -p

1 Like

Is the sysctl.conf regenerated periodically in that environment? If not, it seems wrong to append that line to the file every time you build :slight_smile:

If you want a once-off command to increase the limit for the duration of the “session”, you could run sysctl fs.inotify.max_user_watches=524288 instead of the above.

Alternatively, add fs.inotify.max_user_watches=524288 to /etc/sysctl.conf and don’t add it to your .gitlab-ci.yml.

See this comment for others you might want to set:

https://github.com/expo/expo-cli/issues/277#issuecomment-452685177

Thanks @wodin for the link and suggestion. Running the command to increase the file watcher limit solved the issue.

1 Like

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.