nodejs / node

Node.js JavaScript runtime ✨🐢🚀✨
https://nodejs.org
Other
106.98k stars 29.24k forks source link

FSWatch / readdirSync Crash with more of 20K OR 2k Files Oneshot #41602

Open aaferna opened 2 years ago

aaferna commented 2 years ago

Version

Node 16 (Compiled with PKG 5.5

Platform

Windows 10 21H2

Subsystem

?

What steps will reproduce the bug?

List with readdirSync one directory with more of 2K Files. In my case, 20K fail the process of listing.

How often does it reproduce? Is there a required condition?

the code

readdirSync(a.dir).map((file) =>{

                            fileToTXT(a.dir+file, LogFileNameRespwn)
                        })

with readdir the same thing happens

What is the expected behavior?

node:events:371 throw er; // Unhandled 'error' event ^

Error: UNKNOWN: unknown error, watch at FSEvent.FSWatcher._handle.onchange (node:internal/fs/watchers:204:21) Emitted 'error' event on FSWatcher instance at: at FSEvent.FSWatcher._handle.onchange (node:internal/fs/watchers:210:12) { errno: -4094, syscall: 'watch', code: 'UNKNOWN', filename: null }

What do you see instead?

nop

Additional information

No response

aaferna commented 2 years ago

imagen With chokidar, the same problem happens. Claro uses the same dependency. But, after several tests I see that at 4096 files listed it breaks. Is there a flag that I have to play?

aaferna commented 2 years ago

Try with Node 17.3.1

imagen

aaferna commented 2 years ago

It is not a memory problem, I assigned the flag --options max_old_space_size=4096 to pkg so that nodejs works comfortably and the problem persists.

aaferna commented 2 years ago

im try usePolling: true flag and not change the error.

DavidHGJ commented 2 years ago

i have a similar error, i using webpack with laravel mix

aaferna commented 2 years ago

Hi Team, Any news on the case?

liuxingbaoyu commented 2 years ago

This cannot be reproduced on my local, a folder with 8000+ files.

bnoordhuis commented 2 years ago

@aaferna can you try applying this patch and seeing what it prints?

diff --git a/deps/uv/src/win/fs-event.c b/deps/uv/src/win/fs-event.c
index 76da077551d..63151f8c50c 100644
--- a/deps/uv/src/win/fs-event.c
+++ b/deps/uv/src/win/fs-event.c
@@ -566,16 +566,17 @@ void uv_process_fs_event_req(uv_loop_t* loop, uv_req_t* req,

         offset = file_info->NextEntryOffset;
       } while (offset && !(handle->flags & UV_HANDLE_CLOSING));
     } else {
       handle->cb(handle, NULL, UV_CHANGE, 0);
     }
   } else {
     err = GET_REQ_ERROR(req);
+    printf("ReadDirectoryChanges error %d\n", err);
     handle->cb(handle, NULL, 0, uv_translate_sys_error(err));
   }

   if (handle->flags & UV_HANDLE_CLOSING) {
     uv_want_endgame(loop, (uv_handle_t*)handle);
   } else if (uv__is_active(handle)) {
     uv_fs_event_queue_readdirchanges(loop, handle);
   }

If building from source is too much hassle, you can try setting a breakpoint with a debugger and inspect the value of err.