Skip to content

Unable to run app due to "too many open files" #35

Open

Description

@robertgdev

What were you trying to do?

Trying to run the default install of NativePHP.

What happened?

I installed NativePHP into a new Laravel app and followed the instructions to build the app.

When I try to run the app, I get the following:

Unzipping PHP binary from /home/rng/work/NativePhp/vendor/nativephp/php-bin/bin/linux/x64/php-8.4.zip to /home/rng/work/NativePhp/vendor/nativephp/desktop/resources/build/php
Copied PHP binary to  /home/rng/work/NativePhp/vendor/nativephp/desktop/resources/build/php/php
renderer and preload config is missing
vite v7.1.6 building SSR bundle for development...

watching for file changes...

build started...
✓ 37 modules transformed.
node:internal/fs/watchers:254
    const error = new UVException({
                  ^

Error: EMFILE: too many open files, watch '/home/rng/work/NativePhp/app/Providers/NativeAppServiceProvider.php'
    at FSWatcher.<computed> (node:internal/fs/watchers:254:19)
    at Object.watch (node:fs:2549:36)
    at createFsWatchInstance (file:///home/rng/work/NativePhp/vendor/nativephp/desktop/resources/electron/node_modules/rollup/dist/es/shared/watch.js:6957:16)
    at setFsWatchListener (file:///home/rng/work/NativePhp/vendor/nativephp/desktop/resources/electron/node_modules/rollup/dist/es/shared/watch.js:7004:16)
    at NodeFsHandler._watchWithNodeFs (file:///home/rng/work/NativePhp/vendor/nativephp/desktop/resources/electron/node_modules/rollup/dist/es/shared/watch.js:7159:15)
    at NodeFsHandler._handleFile (file:///home/rng/work/NativePhp/vendor/nativephp/desktop/resources/electron/node_modules/rollup/dist/es/shared/watch.js:7223:24)
    at NodeFsHandler._addToNodeFs (file:///home/rng/work/NativePhp/vendor/nativephp/desktop/resources/electron/node_modules/rollup/dist/es/shared/watch.js:7465:22)
    at async file:///home/rng/work/NativePhp/vendor/nativephp/desktop/resources/electron/node_modules/rollup/dist/es/shared/watch.js:8477:22
    at async Promise.all (index 0)
Emitted 'error' event on FSWatcher instance at:
    at FSWatcher._handleError (file:///home/rng/work/NativePhp/vendor/nativephp/desktop/resources/electron/node_modules/rollup/dist/es/shared/watch.js:8673:11)
    at NodeFsHandler._addToNodeFs (file:///home/rng/work/NativePhp/vendor/nativephp/desktop/resources/electron/node_modules/rollup/dist/es/shared/watch.js:7473:19)
    at async file:///home/rng/work/NativePhp/vendor/nativephp/desktop/resources/electron/node_modules/rollup/dist/es/shared/watch.js:8477:22
    at async Promise.all (index 0) {
  errno: -24,
  syscall: 'watch',
  code: 'EMFILE',
  path: '/home/rng/work/NativePhp/app/Providers/NativeAppServiceProvider.php',
  filename: '/home/rng/work/NativePhp/app/Providers/NativeAppServiceProvider.php'
}

I should note that I have generously increased my system limits to try to work around this but the issue persists:

~/work/NativePhp$ ulimit -n
65536
~/work/NativePhp$ cat /proc/sys/fs/inotify/max_user_watches
4097152

For reference, here is my composer.json require section:

    "require": {
        "php": "^8.2",
        "inertiajs/inertia-laravel": "^2.0",
        "laravel/framework": "^12.0",
        "laravel/tinker": "^2.10.1",
        "laravel/wayfinder": "^0.1.11",
        "nativephp/desktop": "^2.0"
    },
    "require-dev": {
        "fakerphp/faker": "^1.23",
        "laravel/pail": "^1.2.2",
        "laravel/pint": "^1.24",
        "laravel/sail": "^1.41",
        "mockery/mockery": "^1.6",
        "nunomaduro/collision": "^8.6",
        "pestphp/pest": "^4.1",
        "pestphp/pest-plugin-laravel": "^4.0"
    },

but the issue persists. Even if we're watching /vendor and /node_modules (I don't think we should, maybe they can be excluded), I think this error is a sign of something weird going on.

How to reproduce the bug

See above.

Debug Output

{
"Environment": {
"PHP": {
"Version": "8.4.5",
"Path": "/usr/bin/php8.4"
},
"Laravel": {
"Version": "12.35.1",
"ConfigCached": false,
"RoutesCached": false,
"DebugEnabled": true
},
"Node": {
"Version": "v22.21.0",
"Path": "/usr/bin/node"
},
"NPM": {
"Version": "10.9.4",
"Path": "/usr/bin/npm"
},
"OperatingSystem": "Linux"
},
"NativePHP": {
"Versions": {
"nativephp/desktop": "2.0.1.0",
"nativephp/php-bin": "1.1.1.0"
},
"Configuration": {
"Provider": "App\Providers\NativeAppServiceProvider",
"BuildHooks": {
"Pre": [],
"Post": []
},
"NotarizationEnabled": false,
"AzureTrustedSigningEnabled": false,
"CustomPHPBinary": false
}
}
}

Which operating systems have you seen this occur on?

KUbuntu 25.04

Notes

Please note that I'm not sure that this is a bug or some kind of weird setup issue. Feel free to reclassify.

Activity

  1. gwleuverink commented on Oct 28, 2025

    @gwleuverink
    Collaborator

    Hi @rgasch. Thanks for your detailed report.

    Going by the errors it seems like this might be related to this line here:

    this.addWatchFile(join(process.env.APP_PATH, 'app', 'Providers', 'NativeAppServiceProvider.php'));

    It instructs vite to watch your service provider & reload when anything changes. Can you confirm that's the issue by removing that line?

  2. robertgdev commented on Oct 28, 2025

    @robertgdev
    Author

    Yes, when commenting out this line, the system starts.

    I'll leave this issue open so you can decide if it warrants a patch from your side; please feel free to close it when you think it's appropriate.

    Thank you for your help!

  3. gwleuverink commented on Oct 28, 2025

    @gwleuverink
    Collaborator

    Dubious. What's passed to that function is just a path to a single file. But the error suggests it's hitting the file open limit, which I agree is weird.

    It's using the electron-vite dev --watch command under the hood while running native:run. It almost seems like vite is using a different watching strategy for the entire project altogether when passing a single outside file to watch.

    I wonder what files are actually being watched in both scenarios (with the offending line present/commented out)

    Could you run strace -e inotify_add_watch -p $(pgrep -f vite)

  4. robertgdev commented on Oct 29, 2025

    @robertgdev
    Author

    If I do

    artisan native:run
    

    and then

    strace -e inotify_add_watch -p $(pgrep -f vite)
    

    I get an error:

    > strace -e inotify_add_watch -p $(pgrep -f vite)
    strace: Cannot find executable '3816223'
    

    Am I doing this right?

  5. gwleuverink commented on Oct 29, 2025

    @gwleuverink
    Collaborator

    Hmm perhaps it needs to be electron-vite instead? I’m not sure, I’m not on Linux so can’t verify

  6. robertgdev commented on Oct 29, 2025

    @robertgdev
    Author

    I'm a little doubtful the command you gave is correct. I did the following:

    ps aux|grep vite
    rng      4065286  0.0  0.0   2892  1756 pts/7    S+   18:40   0:00 sh -c cross-env node php.js && electron-vite dev --watch
    rng      4065305  2.8  0.1 23386216 112036 pts/7 Sl+  18:40   0:00 node /home/rng/work/NativePhp/vendor/nativephp/desktop/resources/electron/node_modules/.bin/electron-vite dev --watch
    

    Using your script, I get an error. But if I do

    sudo strace -e inotify_add_watch -p 4065286
    

    it works (in the sense that it attaches to the process). However, these commands (for both process IDs) generate no output.

    If I run

     sudo strace -p 4065305
    

    I get this output about once a second:

    epoll_pwait(15, [{events=EPOLLIN, data=0x1a}], 1024, -1, NULL, 8) = 1
    read(26, "\35\0\0\0\220\2\0\0\6\1\0\0\0\7\0\0\0command\3\4\0\0\0pin"..., 65536) = 33
    write(24, "\t\0\0\0\221\2\0\0\6\0\0\0\0", 13) = 13
    epoll_pwait(15, [], 1024, 0, NULL, 8)   = 0
    

    Please advise how to proceed c.q. better diagnose this. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions