Error when running exp publish: socket hang up

#1

Whenever i try to run exp publish on CircleCI (either Ubuntu 12.04 or 14.04, w/ node 7.10.0), i run into the following error:

[exp] Making sure project is set up correctly...
[exp] Your project looks good!
[exp] Unable to find an existing exp instance for this directory, starting a new one...
[exp] Starting React Native packager...
[exp] Scanning 847 folders for symlinks in /home/circleci/repo/node_modules (23ms)
[exp] Loading dependency graph.
[exp] Running packager on port 19001.
[exp] Publishing...
[exp] Building iOS bundle
[exp] socket hang up
Building JavaScript bundle [] 0%Error: socket hang up
    at createHangUpError (_http_client.js:302:15)
    at Socket.socketOnEnd (_http_client.js:394:23)
    at emitNone (events.js:91:20)
    at Socket.emit (events.js:188:7)
    at endReadableNT (_stream_readable.js:975:12)
    at _combinedTickCallback (internal/process/next_tick.js:80:11)
    at process._tickCallback (internal/process/next_tick.js:104:9)
Exited with code 1

Any ideas? Thanks much!

Debug release stopped taking changes
RequestError: Error: socket hang up while after using "exp build:android" or "exp publish"
Travis: exp publish
Can't `expo publish`, "socket hang up"
#2

Could you try setting adding a key in your app.json (under the expo) key called packagerOpts, and then setting that to:

{
  nonPersistent: true
}

This will disable watch mode in the packager, which may help here.

Let me know!

#3

Thanks for the tip, @skevy!

After adding that flag to the packagerOpts section, the packager seems to not recognize that option and hang:

circleci@ed1625d76dec:~/repo$ exp publish
[exp] Making sure project is set up correctly...
[exp] Your project looks good!
[exp] Unable to find an existing exp instance for this directory, starting a new one...
[exp] Starting React Native packager...
[exp] Scanning 847 folders for symlinks in /home/circleci/repo/node_modules (11ms)
[exp] Usage: cli [options] mand]
[exp]
[exp]
[exp]   Options:
[exp]
[exp]     -V, --version  output the version number
[exp]     -h, --help     output usage information
[exp]
[exp]
[exp]   Commands:
[exp]
[exp]     start [options]                    starts the webserver
[exp]     run-ios [options]                  builds your app and starts it on iOS simulator
[exp]     run-android [options]              builds your app and starts it on a connected Android emulator or device
[exp]     new-library [options]              generates a native library bridge
[exp]     bundle [options]                   builds the javascript bundle for offline use
[exp]     unbundle [options]                 builds javascript as "unbundle" for offline use
[exp]     eject [options]                    Re-create the iOS and Android folders and native code
[exp]     link [options] [packageName]       links all native dependencies (updates native build files)
[exp]     unlink [options] <packageName>     unlink native dependency
[exp]     install [options] <packageName>    install and link native dependencies
[exp]     uninstall [options] <packageName>  uninstall and unlink native dependencies
[exp]     upgrade [options]                  upgrade your app's template files to the latest version; run this after updating the react-native version in your package.json and running npm install
[exp]     log-android [options]              starts adb logcat
[exp]     log-ios [options]                  starts iOS device syslog tail
^C
Stopping packager...
Packager stopped.

Here’s my app.json for reference:

{
  "expo": {
    "name": "Fuzzy Pet Health",
    "sdkVersion": "19.0.0",
    "icon": "./App/Images/app-icon.png",
    "version": "2.0.0",
    "slug": "fuzzy-mobile",
    "ios": {
      "bundleIdentifier": "com.yourfuzzy.fuzzyhealth"
    },
    "android": {
      "package": "com.yourfuzzy.fuzzy"
    },
    "packagerOpts": {
      "nonPersistent": true
    }
  }
}

Thanks again for your help! I really appreciate it.

#4

:confused: I’m sorry it didn’t work.

I just made a change in XDL (the library that underpins exp) to allow for this packager option to be set. That change will go it in the next release.

#5

Ahh, thanks for pointing me towards XDL!

After digging into how it generates arguments for react-native-cli from the value of packagerOpts and in what format react-native-cli expects arguments to be in, I think I came to the same realization you did:

Interestingly, since the CLI allows duplicate boolean arguments, I can very ugly-ly hack my way around this until your commit is shipped by using the following monstrosity:

"packagerOpts": {
      "nonPersistent": "--nonPersistent"
}

Thank you so much for the quick fix!

1 Like
#6

Hey guys, I have the same issue and adding this to my app.json allows it to build…

… but it stops the packager from picking up changes on the file system when developing, which is painful to say the least!

Any ideas how to get around this? I can probably have my CI process inject the options into the file but it seems a bit hacky…

#7

Hello,

Try running yarn start / npm run start at your project. When I had this issue it was related the warning below because I’ve restarted my pc.

See https://git.io/v5vcn for more information, either install watchman or run the following snippet:
sudo sysctl -w fs.inotify.max_user_instances=1024
sudo sysctl -w fs.inotify.max_user_watches=12288
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

When I run the commands it solved the exp start / exp build:android proccess

#8

I tried to use:

"packagerOpts": {
      "nonPersistent": "--nonPersistent"
}

but the socket hang up error persists. Some other solution?

#9

I’ve had the same problem once I upgraded to Expo SDK 31. Builds in Travis were fine with SDK 30, but now it’s suddenly busting on 31.

I’ve tried using

"packagerOpts": {
  "nonPersistent": true
}

and

"packagerOpts": {
  "nonPersistent": "--nonPersistent"
}

but both still result in the same error:

Building iOS bundle
fs.js:1384
    throw error;
    ^

Error: watch /home/travis/build/transparentclassroom/TransparentClassroom/node_modules/escodegen/node_modules/source-map/lib ENOSPC
    at FSWatcher.start (fs.js:1382:19)
    at Object.fs.watch (fs.js:1408:11)
    at NodeWatcher.watchdir (/home/travis/build/transparentclassroom/TransparentClassroom/frontend/native/node_modules/sane/src/node_watcher.js:175:20)
    at Walker.<anonymous> (/home/travis/build/transparentclassroom/TransparentClassroom/frontend/native/node_modules/sane/src/common.js:116:12)
    at emitTwo (events.js:126:13)
    at Walker.emit (events.js:214:7)
    at /home/travis/build/transparentclassroom/TransparentClassroom/frontend/native/node_modules/walker/lib/walker.js:69:16
    at go$readdir$cb (/home/travis/build/transparentclassroom/TransparentClassroom/frontend/native/node_modules/graceful-fs/graceful-fs.js:162:14)
    at FSReqWrap.oncomplete (fs.js:135:15)
socket hang up

I’ve also scoured our directory structure and haven’t found any directories with UTF-8 characters, I saw that as also being a problem…

Help?

4 Likes
#10

tl;dr:

Try this: echo 'fs.inotify.max_user_watches=524288' | sudo tee -a /etc/sysctl.conf && sudo sysctl -p

Long version

Okay, so we sussed out our iteration of this problem… the ENOSPC error code was critical in solving the problem. It was fixed with this line:

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

inotify is the system that watchman (a file watcher made by Facebook) uses, and watchman is used by Expo. It appears for Travis we would hit the limit of watches and report we had no more space, but actually we just ran out of file descriptors. The line above increases that amount. More here. You could also probably try installing watchman, but that seemed pretty difficult to do on Ubuntu and the above command worked for us so whatever.

In our particular case, we were using default Travis builds, which it turns out runs on Ubuntu 14. It didn’t particularly like the command above, so we switched to using Ubuntu 16 (Xenial) and had to enable sudo mode. So, for Travis folks, here’s the salient details in our .travis.yml file:

dist: xenial

# We needed to specify PostgreSQL 10 once we switched to Ubuntu 16
# you might need this as well
addons:
  postgresql: "10"

# then add the script however you want

We also noticed that it would choke when we used the && with the command, so we split it into two separate operations:

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

Hope this is helpful to other people!

2 Likes