oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
73.6k stars 2.72k forks source link

[windows] Implement fs.watch on Windows #8361

Closed Jarred-Sumner closed 8 months ago

Jarred-Sumner commented 8 months ago

@cirospaciari fs.watch test is panicking:

test\js\node\watch\fs.watch.test.ts:
  ✓ fs.watch > non-persistent watcher should not block the event loop [65.90ms]
  ✓ fs.watch > watcher should close and not block the event loop [73.78ms]
  ✓ fs.watch > unref watcher should not block the event loop [76.06ms]
  ✓ fs.watch > should work with relative files [81.34ms]

  Error: 
        at 
        at 
        at 
        at 
        at 
        at 
        at 
        at 
        at 
        at 
        at 
        at 
        at 
        at 
        at 
        at 
        at 
        at 
        at 
        at 
        at 
        at 
        at 
        at 
        at 
        at 
        at 
        at 
        at 
        at 
        at 
        at 
  TimeoutError: The operation timed out.
  ✗ fs.watch > add file/folder to folder [3000.59ms]
  Segmentation fault at address 0x42cf4513004
  ???:?:?: 0x7ff74b38054b in ??? (???)
  ???:?:?: 0x7ff74b37ffaf in ??? (???)
  ???:?:?: 0x7ff74ae5c068 in ??? (???)
  ???:?:?: 0x7ff74aa54b02 in ??? (???)
  ???:?:?: 0x7ff74c57dbda in ??? (???)
  ???:?:?: 0x7ff74a729eb7 in ??? (???)
  ???:?:?: 0x7ff74a78b4bc in ??? (???)
  ???:?:?: 0x7ff74a521492 in ??? (???)
  ???:?:?: 0x7ff74c8d12af in ??? (???)
  ???:?:?: 0x7ffd0b4e4ddf in ??? (KERNEL32.DLL)
  ???:?:?: 0x7ffd0b6bedaa in ??? (ntdll.dll)
  bun test v1.0.25-canary.27 (58260825)
Jarred-Sumner commented 8 months ago

I'm able to reproduce in a debug build eventually:

call stack:

bun-debug.exe!abort() Line 563 (c:/bun/.cache/zig/lib/std/os.zig:563)
bun-debug.exe!handleSegfaultWindowsExtra(os.windows.EXCEPTION_POINTERS * info, unsigned char msg, []u8 label) Line 2621 (c:/bun/.cache/zig/lib/std/debug.zig:2621)
bun-debug.exe!handleSegfaultWindows(os.windows.EXCEPTION_POINTERS * info) Line 2592 (c:/bun/.cache/zig/lib/std/debug.zig:2592)
ntdll.dll!00007ffe04a47a8a() (Unknown Source:0)
ntdll.dll!00007ffe049ee242() (Unknown Source:0)
ntdll.dll!00007ffe04a7340e() (Unknown Source:0)
bun-debug.exe!uv__process_fs_event_req() (Unknown Source:0)
bun-debug.exe!uv_run() (Unknown Source:0)
bun-debug.exe!uv_run() (Unknown Source:0)
bun-debug.exe!us_loop_run(us_loop_t * loop) Line 202 (c:/bun/packages/bun-usockets/src/eventing/libuv.c:202)
bun-debug.exe!run(src.deps.uws.UVLoop * this) Line 2540 (c:/bun/src/deps/uws.zig:2540)
bun-debug.exe!autoTick(src.bun.js.event_loop.EventLoop * this) Line 1113 (c:/bun/src/bun.js/event_loop.zig:1113)
bun-debug.exe!run(builtin.StackTrace * reporter, src.cli.test_command.CommandLineReporter * vm, src.bun.js.javascript.VirtualMachine * file_name, []u8 is_last, mem.Allocator *) Line 1072 (c:/bun/src/cli/test_command.zig:1072)
bun-debug.exe!begin(src.cli.test_command.TestCommand.runAllTests.Context * this) Line 962 (c:/bun/src/cli/test_command.zig:962)
bun-debug.exe!00007ff6ce2005bc() Line 104 (c:/bun/src/bun.js/javascript.zig:104)
bun-debug.exe!JSC__VM__holdAPILock(JSC::VM * arg0, void * ctx, void(*)(void *) callback) Line 4548 (c:/bun/src/bun.js/bindings/bindings.cpp:4548)
[Inline Frame] bun-debug.exe!cppFn() Line 186 (c:/bun/src/bun.js/bindings/shimmer.zig:186)
bun-debug.exe!00007ff6cdb536b9() Line 5299 (c:/bun/src/bun.js/bindings/bindings.zig:5299)
[Inline Frame] bun-debug.exe!runWithAPILock() Line 2330 (c:/bun/src/bun.js/javascript.zig:2330)
bun-debug.exe!runAllTests(src.cli.test_command.CommandLineReporter * reporter_, src.bun.js.javascript.VirtualMachine * vm_, []src.string_types.PathString files_, mem.Allocator * allocator_) Line 971 (c:/bun/src/cli/test_command.zig:971)
cirospaciari commented 8 months ago

Will take a look probably is a UAF

Jarred-Sumner commented 8 months ago

@cirospaciari

The following does not emit any events:

const path = require("path");
const fs = require("fs");
const watchPath = path.join(process.cwd(), "src");

const watcher = fs.watch(watchPath, { recursive: true }, (event, file) => {
  try {
    console.log(`Detected ${event} on ${file}...`);
    reloadPacks();
  } catch (e) {
    console.error(e);
  }
});

Then, in a separate shell, write hey to src/hey.txt

lightyisreal commented 8 months ago

Any progress?