Running Electron compilation in Dockerfile throws "too many open files" exception


#1

I have an Electron-based application that I want to run on Resin. Normally we compile the Electron app into a binary in the Dockerfile, however on pushing to resin:master I get the following error. Could this be caused by a setting on the Resin host running Docker, or is there some way to resolve on my end? The same command runs normally in local Docker and in Codeship Docker, where we were building the app before.

[Build]    Step 25/26 : RUN ./node_modules/.bin/electron-forge make --platform=linux --arch=x64
[Build]     ---> Running in abc8c692d18e
[Build]    ✔ Checking your system
[Build]    ✔ Resolving Forge Config
[Build]    We need to package your application before we can make it
[Build]    
[Build]    An unhandled exception has occurred inside Forge:
[Build]    EMFILE: too many open files, open '/tmp/electron-forge/.runtime.config'
[Build]    Error: EMFILE: too many open files, open '/tmp/electron-forge/.runtime.config'
[Build]        at Object.fs.openSync (fs.js:653:18)
[Build]        at Object.fs.writeFileSync (fs.js:1300:33)
[Build]        at BasicConfigStore.reset (/usr/src/app/node_modules/electron-forge/dist/util/config.js:68:23)
[Build]        at process.BasicConfigStore.process.on (/usr/src/app/node_modules/electron-forge/dist/util/config.js:43:12)
[Build]        at emitOne (events.js:120:20)
[Build]        at process.emit (events.js:210:7)
[Build]    Removing intermediate container abc8c692d18e
[Error]    Build failed: The command '/bin/sh -c ./node_modules/.bin/electron-forge make --platform=linux --arch=x64' returned a non-zero code: 1

#4

Found this related to running out of file descriptors in Docker, maybe this is a similar issue? https://github.com/moby/moby/issues/19124


#5

It looks like you are likely hitting the the file descriptor limit on our build servers. I’ll talk to our devops team to investigate further.


#6

Does this error happen consistently or only when running a build at certain times?


#9

Thanks for your help. The problem happened consistently for me every time I tried yesterday and today.


#10

One possible workaround is to use our emulated builder like so: git push resin master:resin-emulated. This might have a higher file descriptor limit, but I can’t say for sure.


#11

I tried pushing to resin-emulated and unfortunately got the same error :frowning:


#12

Hello,

the fact that you hit the same error in the emulated builder which was probably running only your job indicates that you hit docker’s limits (which follows our system’s limits) or something weird is happening during bid, like the electron-forge leaking file descriptors.

I’d like to recommend to try to build it locally and see if you hit any similar errors.

Best,
ilias


#13

I tried building the same image locally and it succeeded:

Step 22/23 : RUN ./node_modules/.bin/electron-forge make --platform=linux --arch=x64
 ---> Running in 8f817b4212c0
✔ Checking your system
✔ Resolving Forge Config
We need to package your application before we can make it
✔ Preparing to Package Application for arch: x64
✔ Compiling Application
✔ Preparing native dependencies: 1 / 1
✔ Packaging Application
Making for the following targets:
✔ Making for target: deb - On platform: linux - For arch: x64
 ---> 16e6c33de71e
Removing intermediate container 8f817b4212c0
Step 23/23 : CMD bash /usr/src/app/start.sh
 ---> Running in d5078caa9867
 ---> 9b1e79250969
Removing intermediate container d5078caa9867
Successfully built 9b1e79250969

This is on OSX using docker-machine. I don’t remember configuring anything special to get electron-forge to work before, it’s always worked for me locally in the past.