Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Segmentation fault when running in watch mode in Node 20.12.x or greater #173

Closed
joshmossas opened this issue Apr 17, 2024 · 5 comments
Closed

Comments

@joshmossas
Copy link

joshmossas commented Apr 17, 2024

Environment

Software Version
NodeJS v20.12.2
Operating System Pop!_OS 22.04 LTS
Listhen v1.7.2

Reproduction

https://github.com/joshmossas/listhen-watch-segfault

Describe the bug

Running listhen in watch mode causes you to get the following error:

Segmentation fault (core dumped)
 ELIFECYCLE  Command failed with exit code 139.

This is true if you use the cli (listhen ./my-file.ts --watch) or if you call listenAndWatch() directly.

Additional context

Downgrading to NodeJS v20.11.1 causes everything to run normally.

I haven't tried to reproduce on other operating systems. So I can only confirm that this is happening in Linux.

Logs

No response

@joshmossas
Copy link
Author

joshmossas commented Apr 17, 2024

I've identified the cause. For some reason dynamically importing @parcel/watcher in src/server/watcher.ts causes a segfault when you try to use the subscribe() function

const subscribe = await import("@parcel/watcher")

If you import subscribe() from @parcel/watcher normally the segfault doesn't occur anymore.

So the change I made to get things working looks like this:

// top of file
import { subscribe, type AsyncSubscription } from "@parcel/watcher";

// registering subscription (line 55)
watcher = await subscribe(
  devServer.cwd,
  ... rest
)

I'm aware this fix isn't ideal because we it no longer dynamically imports from @parcel/watcher-wasm if using @parcel/watcher fails. But at least it provides a starting point for fixing the issue.

@joshmossas
Copy link
Author

Okay I'm not able to reproduce on MacOS so this seems to be Linux specific.

@joshmossas joshmossas changed the title Segmentation fault when running in watch mode in Node 20.12 or greater Segmentation fault when running in watch mode in Node 20.12.x or greater Apr 18, 2024
@pi0
Copy link
Member

pi0 commented Apr 18, 2024

Hi dear @joshmossas. Can you please try await import("@parcel/watcher") in a simple test.mjs file alone to see if can still reproduce?

Lazy loading of watcher is essential for listhen because we don't need it in all paths. We might track this issue from https://github.com/parcel-bundler/watcher or Node.js seems lower level bug.

@joshmossas
Copy link
Author

joshmossas commented Apr 18, 2024

Okay so it looks like the source of the issue is actually this. parcel-bundler/watcher#170

Listhen is using wildcard ignores by default, which is triggering this bug

ignore: options.ignore || [

You can disregard my comment about lazy loading being the issue. In my fork turns out I accidentally imported @parcel/watcher-wasm which doesn't have this bug. 😅

I've also reverted to using lazy loading in my fork (with @parcel/watcher-wasm only) and it works.

@pi0
Copy link
Member

pi0 commented Apr 19, 2024

Thanks for checking upstream 🙏🏼 okay let's track from there then. i will also subscribe to see what happens.

@pi0 pi0 closed this as not planned Won't fix, can't repro, duplicate, stale Apr 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants