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

napi_create_string_utf8 assertion failed #355

Closed
nickbabcock opened this issue Jan 9, 2021 · 26 comments · Fixed by #356
Closed

napi_create_string_utf8 assertion failed #355

nickbabcock opened this issue Jan 9, 2021 · 26 comments · Fixed by #356
Assignees

Comments

@nickbabcock
Copy link

nickbabcock commented Jan 9, 2021

In the last couple days, my regularly scheduled builds have been failing with:

Assertion failed: (napi_create_string_utf8(env, events->events[idx].path, NAPI_AUTO_LENGTH, &args[0]) == napi_ok), function fse_dispatch_event, file ../src/fsevents.c, line 147.
Abort trap: 6

Failures occur on latest versions of node 10, 12, and 14.

I do not have a minimum reproducible example, but wanted to create an issue to create awareness in case I'm not the only person with this problem. All I can offer right now is this reproduction that uses fsevents through a transitive relation (so may not offer much help).

git clone https://github.com/nickbabcock/highwayhasher.git
cd highwayhasher/verifier
npm install
npm test
@paulmillr
Copy link
Member

It seems like you're using the old fsevents version. Obviously you're not using it, your dependency is consuming fsevents.

So you'll need to find which dependency it is. I've tried installing your test example, but was not able to due to puppeteer.

@nickbabcock
Copy link
Author

It seems like you're using the old fsevents version

Very true, but the error started triggering in the last few days (coinciding with the release of fsevents and chokidar) and I can see fsevents@2.3.1 being used by jest and karma. It appears no other dependency in the tree down to fsevents / chokidar has seen a release in the last couple days. The old version (1.2.13) is 8 months old and so I wouldn't think it's behavior would change so suddenly (maybe environment updates, but doesn't look like the github actions macos environment has changed in the last few days).

@paulmillr
Copy link
Member

I'm pretty confident though that we've fixed this error in 2.2

@nickbabcock
Copy link
Author

I was able to get this to work it by downloading fsevents@2.1.3 (ie what's referenced by chokidar@3.4.3) and copying the fsevents.{js,node} from 2.1.3 into an fsevents 2.2.x or 2.3.x installation dir. This heavily implies the regression was introduced in fsevents 2.2 and still present fsevents 2.3

@tripodsan
Copy link

downgrading to chokidar@3.4.3 worked for me.

@paulmillr
Copy link
Member

If someone can create reproducible repo this would help

@sunknudsen
Copy link

sunknudsen commented Jan 31, 2021

Hey @paulmillr,

If someone can create reproducible repo this would help

I am debugging a chokidar issue and tried to access fsevents directly (after reading this warning on the Webpack docs) and I believe I am running into this issue.

Running the following code on macOS Catalina 10.15.7 and editing (I used Visual Studio Code for this experiment) a file called foo within tests a few times in a row throws the following error consistently.

Assertion failed: (napi_create_string_utf8(env, events->events[idx].path, NAPI_AUTO_LENGTH, &args[0]) == napi_ok), function fse_dispatch_event, file ../src/fsevents.c, line 147.

Node version: 14.15.1
fsevents version: 2.3.1

const fsevents = require('fsevents');
fsevents.watch(`${__dirname}/tests`, (path, flags, id) => {
  const info = fsevents.getInfo(path, flags, id);
  console.log(info)
});
setInterval(() => {
  console.log("tick")
}, 60000);

I packaged this code in a repo.

@sunknudsen
Copy link

I installed a fresh copy of Node (version 14.15.4), Visual Studio Code (version 1.52.1) and fsevents (version 2.3.2) on another MacBook Pro I use for tests (clean install of macOS Catalina version 10.15.7) and was able to reproduce the above assertion error (which likely means it's not a filesystem corruption issue).

I then tried editing foo using the pre-installed version of vim (version 8.1.2292) and a strange edge case occurred.

No watch events were triggered when editing foo and saving to file using :w! (even though I confirm file was edited using Visual Studio Code).

What is even stranger is that once the file was edited using vim (no watch event triggered), editing that same file in Visual Studio Code no longer triggered watch events.

So... clearly something is broken either at the fsevents level or downstream at the macOS level.

Unfortunately, I can't debug this deeper as I don't have the required knowledge.

I believe this is what is causing issues with chokidar and create-react-app.

@sunknudsen
Copy link

I just created a repo that includes the above code and instructions on how to reproduce this issue.

Please let me know if you guys also hit this issue using my experiment.

@yss14
Copy link

yss14 commented Jan 31, 2021

I also tried to reproduce the issue with your demo repo.
After saving the file about ~30 times the error occured! (tried it multiple times)

Assertion failed: (napi_create_string_utf8(env, events->events[idx].path, NAPI_AUTO_LENGTH, &args[0]) == napi_ok), function fse_dispatch_event, file ../src/fsevents.c, line 147.
zsh: abort      node index.js

System: macOS 11.1 (Apple Silicon)
Node: 15.6.0

@sunknudsen
Copy link

Thanks for sharing @yss14.

After saving the file about ~30 times the error occured! (tried it multiple times)

Did you edit the content of foo between runs?

@pipobscure pipobscure self-assigned this Feb 2, 2021
ddeboer added a commit to netwerk-digitaal-erfgoed/dataset-register that referenced this issue Feb 2, 2021
@impowski
Copy link

impowski commented Feb 4, 2021

Big Sur (Apple Silicon), same problem using Nuxt.js, and this one is related to issue nuxt/nuxt#8639

@sunknudsen
Copy link

@impowski Thanks for the bug report.

Have you tried to reproduced the issue using https://github.com/sunknudsen/fsevents-test?

@impowski
Copy link

impowski commented Feb 4, 2021

@sunknudsen yep

@sunknudsen
Copy link

@impowski How many times did you need to edit and save foo before hitting this issue?

@impowski
Copy link

impowski commented Feb 4, 2021

@sunknudsen about 39 times

@sunknudsen
Copy link

Hey @pipobscure,

Have you tried reproducing the issue using https://github.com/sunknudsen/fsevents-test? Is there any other way I (we) can help?

I believe this issue is related to paulmillr/chokidar#1071 and facebook/create-react-app#10475.

If so, fixing this bug would have a significant positive impact on my (and many other's) workflow (and mental health).

Again, please let me know if I (we) can help.

@impowski
Copy link

impowski commented Feb 4, 2021

If so, fixing this bug would have a significant positive impact on my (and many other's) workflow (and mental health).

Haha, yeah, I'm unable to work normally with my Nuxt.js project, the only way is to kill the server make changes and run it again and do that over and over again, my mental health is clearly in decline right now 😭

@impowski
Copy link

impowski commented Feb 4, 2021

I've tried node versions v15.8.0 and v12.20.1 and it doesn't help at all, adding fsevents or chokidar same thing. So I guess it's not a node version related problem.

@pipobscure
Copy link
Contributor

I've found the reason for the crash. I just don't have a solution yet. It looks like if it doesn't creash (because if(cause) ) then it just stops delivering events, so equally useful.

I seem to be in for a longish night.

@sunknudsen
Copy link

Thanks so much for looking into this issue @pipobscure. ❤️

@impowski
Copy link

impowski commented Feb 4, 2021

@pipobscure thanks a lot

pipobscure added a commit that referenced this issue Feb 4, 2021
@pipobscure
Copy link
Contributor

Well the long night is over. I have found the issue.

The test script has a bug (that also triggers this) sunknudsen/fsevents-test#1 fixes it for the test script/

I have also solved the issue that this triggers and created PR #356 with an explanation of what was going on.

TL;DR garbage collection bit me by triggering this and made me hit a missing argument check quite blatantly.

@sunknudsen
Copy link

Hey @pipobscure,

Happy to read the long night is over.

Looking forward to #356. Is there any chance this PR will solve paulmillr/chokidar#1071 and facebook/create-react-app#10475?

Perhaps these upstream issues are not related (I really hope they are).

Thanks for fsevents and for helping us out.

@pipobscure
Copy link
Contributor

@sunknudsen It's quite possible that this is the same cause. Because if the stop gets garbage collected and stops before another event comes in, then it would indeed just stop watching. I'll have to check chokidar and chat with @paulmillr to see if this may be the cause.

pipobscure added a commit that referenced this issue Feb 5, 2021
The `napi_external` that maintains the watch on a file is closured into the *stop* function returned by `fsevents.watch`.
When that `napi_external` is garbage collected, the callback that was passed in is released and becomes uncallable. When it is called depsite this, the `napi_env` that is passed in is `NULL` which is intended by N-API as a signal  that the function is no longer usable. 

I ignored it in the past, because I always retain the stop function. However a test-script like the one provided provokes this. When garbage collection happens, the `napi_external` is cleared. However there may still be events in the pipeline. And that in turn triggers the crash in #355 .

I am now handling the `napi_env` as `NULL` signal properly by just dropping the event. In consequence, if you do not retain the *stop* function event reporting simply stops. And this will happen fairly quickly.

fixes #355
@pipobscure
Copy link
Contributor

Released as v2.3.2

taratatach added a commit to cozy-labs/cozy-desktop that referenced this issue Jul 6, 2021
Upgrading Chokidar leads to an upgrade of `fsevents` (i.e. one of
Chokidar's own dependencies) which received a fix in v2.3.2 preventing
crashes we see in our tests on macOS, especially when run in Github
Actions.

See fsevents/fsevents#355 for more info.
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

Successfully merging a pull request may close this issue.

7 participants