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

Crashing with @napi-rs/canvas buffer, Check failed: result.second, Node.js 16 #2996

Closed
louisfoster opened this issue Nov 29, 2021 · 4 comments
Labels

Comments

@louisfoster
Copy link

  • Using node v16

Are you using the latest version? Is the version currently in use as reported by npm ls sharp the same as the latest version as reported by npm view sharp dist-tags.latest?

yes

What are the steps to reproduce?

When creating a raw buffer .data() from an skr-canvas canvas, then passing it into sharp, sharp crashes (after the first or a few attempts on different instances) when using toBuffer() on this instance:

#
# Fatal error in , line 0
# Check failed: result.second.
#
#
#
#FailureMessage Object: 0x7ffceabb4970
 1: 0xb6f151  [node]
 2: 0x1bf56f4 V8_Fatal(char const*, ...) [node]
 3: 0xfc3f61 v8::internal::GlobalBackingStoreRegistry::Register(std::shared_ptr<v8::internal::BackingStore>) [node]
 4: 0xd151c8 v8::ArrayBuffer::GetBackingStore() [node]
 5: 0xab71b0 napi_get_typedarray_info [node]
 6: 0x7f097c75d1bf sharp::CreateInputDescriptor(Napi::Object) [/node_modules/sharp/build/Release/sharp-linux-x64.node]
 7: 0x7f097c766c2e pipeline(Napi::CallbackInfo const&) [/node_modules/sharp/build/Release/sharp-linux-x64.node]
 8: 0x7f097c773806 Napi::details::CallbackData<Napi::Value (*)(Napi::CallbackInfo const&), Napi::Value>::Wrapper(napi_env__*, napi_callback_info__*) [/node_modules/sharp/build/Release/sharp-linux-x64.node]
 9: 0xaadf9d  [node]
10: 0xd4a18e  [node]
11: 0xd4b5af v8::internal::Builtin_HandleApiCall(int, unsigned long*, v8::internal::Isolate*) [node]
12: 0x15e7959  [node]
Trace/breakpoint trap (core dumped)

That is to say, sometimes it doesn't crash, but after a few re-runs of the function, it always eventually crashes.

What is the output of running npx envinfo --binaries --system?

  System:
    OS: Linux 5.11 Ubuntu 20.04.3 LTS (Focal Fossa)
    CPU: (8) x64 Intel(R) Core(TM) i7-1065G7 CPU @ 1.30GHz
    Memory: 1.83 GB / 15.22 GB
    Container: Yes
    Shell: 5.8 - /usr/bin/zsh
  Binaries:
    Node: 16.13.0 - /usr/bin/node
    Yarn: 1.22.15 - ~/.yarn/bin/yarn
    npm: 8.1.0 - /usr/bin/npm
@lovell
Copy link
Owner

lovell commented Nov 29, 2021

Please can you provide a standalone repo including dependency versions in apackage.json, complete, minimal code and images that allows someone else to reproduce this.

My best guess would be that the @napi-rs/canvas module is susceptible to nodejs/node#32463 and may need to add code to workaround a race condition when multiple Buffer instances can point to the same memory location.

sharp does not do this and is not susceptible to this problem on its own - please see #2196

@lovell lovell added question and removed triage labels Nov 29, 2021
@lovell lovell changed the title Crashing with skr-canvas buffer Crashing with @napi-rs/canvas buffer, Check failed: result.second, Node.js 16 Nov 29, 2021
@yisibl
Copy link

yisibl commented Dec 27, 2021

@Brooooooklyn PTAL, thanks.

@lovell
Copy link
Owner

lovell commented Jan 10, 2022

@louisfoster Were you able to make any progress with this?

@louisfoster
Copy link
Author

Instead of passing the canvas data directly, I use a pool of existing instances, along with buffers they copy to, and do the copy at the end of drawing and pass this copy into sharp. There's almost no noticeable time overhead. There's a separate issue regarding memory not being released but I don't think that's relevant here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants