Replete icon indicating copy to clipboard operation
Replete copied to clipboard

Too many open files

Open SOULPWRD opened this issue 10 months ago • 11 comments

Hi :),

First of all, thank you for this gem.

I'm playing with REPLETE and I have found an issue with this simple code while using Openlayers library:

/*jslint browser */

import Map from "ol/Map.js";
import View from "ol/View.js";
import TileLayer from "ol/layer/Tile.js";
import XYZ from "ol/source/XYZ.js";

const map = new Map({
    layers: [
        new TileLayer({
            source: new XYZ({
                url: "https://tile.openstreetmap.org/{z}/{x}/{y}.png"
            })
        })
    ],
    view: new View({
        center: [0, 0],
        zoom: 2
    })
});

export default Object.freeze(map);

after evaluating this code I'm getting:

Waiting for WEBL: http://localhost:3000
WEBL found.
WEBL found.
WEBL found.
error: Uncaught Error: Too many open files (os error 24)
    at new FsWatcher (ext:runtime/40_fs_events.js:24:17)
    at Object.watchFs (ext:runtime/40_fs_events.js:86:10)
    at ext:deno_node/_fs/_fs_watch.ts:57:21
    at eventLoopTick (ext:core/01_core.js:203:13)

I suppose this is a file descriptor problem related to node/deno.

Thank you in advance for your help.

SOULPWRD avatar Apr 04 '24 13:04 SOULPWRD

Evaluating that snippet results in 157 modules being imported. For each one of those modules, a watcher is created so that Replete will know to reload the file if it is modified. Apparently, 157 watchers is too many for your operating system. May I ask what OS you are using? I have never seen this problem before.

jamesdiacono avatar Apr 04 '24 16:04 jamesdiacono

https://github.com/denoland/deno/issues/17757

jamesdiacono avatar Apr 04 '24 16:04 jamesdiacono

Hi,

been using Ubuntu 22.04 on Windows via WSL(windows subsystem for linux). Maybe that's the issue.

I'll try to run it on Mac and see how it behaves.

SOULPWRD avatar Apr 04 '24 17:04 SOULPWRD

I was able to fix the issue by following this comment. Not sure if it's an appropriate solution, but seems like it fixes the issue.

SOULPWRD avatar Apr 04 '24 20:04 SOULPWRD

I think the real problem is that Deno's watch is more profligate with file descriptors than Node's watch. It is easy to imagine a REPL session where several thousand modules have been imported.

jamesdiacono avatar Apr 05 '24 00:04 jamesdiacono

The latest version of Replete, 0.0.15, handles watch exceptions gracefully. The exception is written to the output, but no longer prevents evaluation. Modules that can not be watched will not be cached, incurring a performance penalty, but at least it will work.

jamesdiacono avatar Apr 05 '24 01:04 jamesdiacono

Could you please test this change with your original inotify configuration?

jamesdiacono avatar Apr 05 '24 01:04 jamesdiacono

Sure.

Maybe I'm missing something, this is my basic setup. I've reverted inotify configuration back to 128. The error persists.

Screenshot 2024-04-05 100344

SOULPWRD avatar Apr 05 '24 08:04 SOULPWRD

It seems that this exception can not be caught after all, owing to some very questionable code: https://github.com/denoland/deno/blob/61f1b8e8dc20846093a8b24a8f511a09bbf09919/ext/node/polyfills/_fs/_fs_watch.ts#L118-L124.

jamesdiacono avatar Apr 05 '24 15:04 jamesdiacono

I've left a comment on https://github.com/denoland/deno/issues/17757.

jamesdiacono avatar Apr 05 '24 16:04 jamesdiacono

Thank you!

SOULPWRD avatar Apr 06 '24 19:04 SOULPWRD