phonegap / phonegap-app-developer

PhoneGap Developer App
app.phonegap.com
Apache License 2.0
2k stars 2.51k forks source link

Error: ENFILE: file table overflow #380

Open screendriver opened 8 years ago

screendriver commented 8 years ago
❯ phonegap serve
[phonegap] starting app server...
[phonegap] listening on 192.168.10.1:3000
[phonegap] listening on 192.168.2.1:3000
[phonegap]
[phonegap] ctrl-c to stop the server
[phonegap]
fs.js:584
  return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode);
                                                  ^

Error: ENFILE: file table overflow, open '/Users/me/.nvm/versions/node/v5.1.0/lib/node_modules/phonegap/node_modules/connect-phonegap/res/middleware/deploy.js'
    at Error (native)
    at Object.fs.openSync (fs.js:584:18)
    at Object.fs.readFileSync (fs.js:431:33)
    at injectScript (/Users/me/.nvm/versions/node/v5.1.0/lib/node_modules/phonegap/node_modules/connect-phonegap/lib/middleware/zip.js:40:34)
    at InjectHTML._transform (/Users/me/.nvm/versions/node/v5.1.0/lib/node_modules/phonegap/node_modules/connect-phonegap/lib/middleware/zip.js:62:68)
    at InjectHTML.Transform._read (_stream_transform.js:167:10)
    at InjectHTML.Transform._write (_stream_transform.js:155:12)
    at doWrite (_stream_writable.js:292:12)
    at writeOrBuffer (_stream_writable.js:278:5)
    at InjectHTML.Writable.write (_stream_writable.js:207:11)

I've made a custom build of the App.

surajpindoria commented 8 years ago

Hi @screendriver, what version of PhoneGap are you using?

screendriver commented 8 years ago

5.3.9. I've tested it in a new hello-world App and it seems to work. Unfortunately not in my project. My project is really large so I think this is the problem.

mwbrooks commented 8 years ago

Hey @surajpindoria, @screendriver is a long-time PhoneGap / Dev App user, so I imagine he's tried the basic troubleshooting already.

@screendriver I imagine you're right about the file size. The error is happening when the PhoneGap CLI is compressing your app to be uploaded to the device. On my own system, I've tested it with upwards of 200MB and it's worked in the past.

We can try to recreate it with the following info:

screendriver commented 8 years ago

Hi @mwbrooks,

for the record: we are using SystemJS as module loading system and jspm as package manager. At development time all source files and all dependencies are stored in www. So we have a lot of files. Later, if we want to deploy to production, we are bundling all together in one js file. The phonegap error occurs at development time.

We have a lot of dependencies like React, react-dom, lodash, Moment.js and so on. There are 9540 files at the moment which leads to a directory size of 108 MB and it's getting more and more.

mwbrooks commented 8 years ago

Wow, that sounds like a sophisticated app! Well, I'll try to look into re-creating the 10,000 files scenario since 108MB should not cause an issue.

Often, the fix for large projects is to increase the number of maximum file handles that your system can have open at any given time. It's a common scenario when installing large npm packages or using node to watch directories with a lot of files. Maybe it'll help you as well.

In your ~/.bashrc or ~/.profile, adding the following line and then reload the source:

# npm EMFILE fix (my personal setting, you may need to bump it higher)
ulimit -n 10240
source ~/.bashrc
# or
source ~/.profile
screendriver commented 8 years ago

Hi @mwbrooks,

I will try this in the next couple of days. And yes, we are building a very complex enterprise application. In my example above you can easy reproduce it. Just install a few jspm packages and you have a lot of files :wink:

$ jspm install react react-dom lodash moment buffer uuid url whatwg-fetch oboe eventemitter2 sass.js

That's not so much as it seem.

timkim commented 8 years ago

Hi there,

I've tried to recreate the error but I actually managed to get the app (created about 3k files) to serve. Here are my steps:

$ phonegap -v
5.3.9

$ phonegap create myTest
$ cd myTest/www/
$ jspm install react react-dom lodash moment buffer npm:uuid url npm:whatwg-fetch npm:oboe npm:eventemitter2 sass.js

I wasn't too sure about how all these things were being used, so I just did this in index.html:

<!doctype html>
  <script src="jspm_packages/system.js"></script>
  <script src="config.js"></script>

Then:

$ phonegap serve

It took awhile on my phone to work - it looked like it crapped out on the Extracting... message, but it eventually went through.

screendriver commented 8 years ago

Hi @timkim,

yes, with the dependencies above it does work. Unfortunately we have a lot more. I can't tell you which one exactly at the moment because in my team we are writing a lot of modules / packages / libraries with a lot of dependencies.

But I have great news: with the latest master branch version it seems to work. Unfortunately I have 100% cpu usage at the moment when I run phonegap serve.

timkim commented 8 years ago

Hi @screendriver,

Ya, I'm not surprised the cpu usage shoots through the roof with all the modules. It's a lot of work for phonegap serve to go through thousands of files and try and zip 'em up. Your best bet for performance is to try that production setting where the files are all bundled into one.