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

Random segmentation fault errors #20072

Closed
oscarotero opened this issue Aug 5, 2023 · 14 comments
Closed

Random segmentation fault errors #20072

oscarotero opened this issue Aug 5, 2023 · 14 comments
Assignees
Labels
bug Something isn't working correctly node compat node native extension related to the node-api (.node)

Comments

@oscarotero
Copy link
Contributor

For a long time I'm getting random errors running Lightningcss plugin on Lume:

[1]    81218 done                echo "import 'lume/cli.ts'" | 
       81219 segmentation fault  deno run --unstable -A - "-s"

The Lightningcss library is run via napi and for some weird reason, Deno panick when I add some specific @import rules in my CSS file.

============================================================
Deno has panicked. This is a bug in Deno. Please report this
at https://github.com/denoland/deno/issues/new.
If you can reliably reproduce this panic, include the
reproduction steps and re-run with the RUST_BACKTRACE=1 env
var set and include the backtrace in your report.

Platform: macos x86_64
Version: 1.36.0
Args: ["deno", "run", "--unstable", "-A", "-", "-s"]

thread '<unnamed>' panicked at 'called `Result::unwrap()` on an `Err` value: RecvError', cli/napi/threadsafe_functions.rs:126:17
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Sorry, I cannot be more specific because it doesn't always happen, so I wasn't able to reproduce this error consistently. I think it didn't happen with the wasm version of Lightningcss, so I suspect it's something related with napi.

@bartlomieju
Copy link
Member

Thanks for the report @oscarotero, I do believe this is actually caused by N-API integration. We'll try to look into fixing this. Any chance you could provide a boiled down reproduction?

@bartlomieju bartlomieju added bug Something isn't working correctly node compat node native extension related to the node-api (.node) labels Aug 5, 2023
@oscarotero
Copy link
Contributor Author

After removing the Deno's cache folder, the segmentation fault error has gone but the Deno panick error is still there.

To reproduce it, clone the following repo, go to lighningcss branch and run deno task build.

The panick error is related with the following line https://github.com/lumeland/lume.land/blob/lightningcss/_includes/styles/reset.css#L1. After removing it, it works fine.

@oscarotero
Copy link
Contributor Author

oscarotero commented Aug 8, 2023

I don't know if this is related, but running the tests, sometimes lightningcss stops the testing and shows this message:

lightningcss plugin (only transform) ... ok (87ms)
lightningcss plugin (bundle mode) ... ok (18ms)
deno(52814,0x70000ed31000) malloc: *** error for object 0x7f79b39a9848: pointer being freed was not allocated
deno(52814,0x70000ed31000) malloc: *** set a breakpoint in malloc_error_break to debug

If I run again the tests, they run complete without issues.
Maybe it's something related with the cache?

@bartlomieju
Copy link
Member

@oscarotero I believe this is purely a race condition in our implementation of "thread safe functions" for Node-API. We wanted to rewrite them for some time now. We'll try to look into the problem next week.

@oscarotero
Copy link
Contributor Author

Great, thanks!

@bartlomieju
Copy link
Member

@oscarotero we found the culprit and should fix it shortly, however with your reproduction we are always getting error: Uncaught (in promise) Error. Is that expected?

@oscarotero
Copy link
Contributor Author

oscarotero commented Aug 29, 2023

@bartlomieju Great!
I just tested it after upgrading deno to the canary version and I can confirm it works fine. The returning error is a bug on my side, sorry.

Thank you!

@bartlomieju
Copy link
Member

@oscarotero that's strange, since the PR in question is #20324 and it hasn't landed yet. Anyway, I'll land it in the coming days. Let me know if you encounter any more problems.

@oscarotero
Copy link
Contributor Author

Okay, the panick error still happens randomly (even on canary).
But after fixing the bug in Lume, it's gone.

@oscarotero
Copy link
Contributor Author

Hi again.
Thanks for fixing the panick issue!
Unfortunately, I continue getting random segmentation faults running lightningcss.

imaxe

It happens randomly, once every 3-4 builds. I don't know if it's an issue from Deno or Lightningcss (It doesn't happen with postcss). I've created this branch https://github.com/lumeland/lume.land/tree/lightningcss if you want to take a look.

@oscarotero
Copy link
Contributor Author

Hi again.
Just want to share another example of random error with lightningcss that just happened in the tests: https://github.com/lumeland/lume/actions/runs/6077032533/job/16486035341#step:6:1317

@oscarotero
Copy link
Contributor Author

oscarotero commented Sep 4, 2023

@tsaxking
Copy link

I'm having a similar problem with npm:express, if I add a single middleware function, it gives me the error: /snap/deno/118/wrapper.sh: line 15: 14346 Segmentation fault $SNAP/deno "${@}" then exits the process. It's always the same middleware function, but it still throws that error if all it does is next();.

@devsnek
Copy link
Member

devsnek commented Jun 10, 2024

napi_threadsafe_function was rewritten in #24101 and shouldn't hit this case anymore. Let us know if you run into additional issues.

@devsnek devsnek closed this as completed Jun 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working correctly node compat node native extension related to the node-api (.node)
Projects
None yet
Development

No branches or pull requests

5 participants