Skip to content

When Node addon creates a new isolate, use it to execute JS code and let it triggers GC, it will crash #16658

@fs-eire

Description

@fs-eire
  • Version: v8.5.0 or higher
  • Platform: Darwin/Linux/Windows (x64)
  • Subsystem:
  1. Create a simple Node addon.
  2. In the Init(), create a thread and create a new isolate in that thread.
  3. In the Method(), notify the thread to execute some javascript code.
  4. When the javascript code triggers GC, the process will crash.
  • Crash error on Ubuntu 16.04.2

    #
    # Fatal error in ../deps/v8/src/heap/heap-inl.h, line 228
    # Debug check failed: gc_state_ == NOT_IN_GC.
    #

    #
    # Fatal error in ../deps/v8/src/heap/heap.cc, line 452
    # Debug check failed: !AllowHeapAllocation::IsAllowed() && gc_state_ == NOT_IN_GC.
    #

  • Crash error on macOS Sierra 10.12.6

    node(27735,0x7fffad7f03c0) malloc: *** error for object 0x10231a980: pointer being freed was not allocated
    *** set a breakpoint in malloc_error_break to debug
    node(27735,0x7000075f6000) malloc: *** error for object 0x10231a778: incorrect checksum for freed object - object was probably modified after being freed.
    *** set a breakpoint in malloc_error_break to debug

  • Crash without error outputted to console (Windows7)

Please refer to https://github.com/fs-eire/node-modules-playground/tree/test-node-crash for the code.

Other findings:

  1. If we block the Node main thread, ( put a while-true in the end of the javascript code) the crash will not happen.
  2. The crash always happens when a Full GC is in operation.

We released Napa.js as a Node module sharing the same v8 platform, and created isolates & manipulated them the same way as the sample addon.

A workaround we could think of is to link with a separate v8 shared library if sharing the same platform is not desired. Actually we started by doing that, but afterwards changed to dynamic linking to V8 from Node for easier build and distribution.

Please kindly suggest if this is a bug in Node, or a behavior by design.

Metadata

Metadata

Assignees

No one assigned

    Labels

    v8 engineIssues and PRs related to the V8 dependency.v8 platformIssues and PRs related to Node's v8::Platform implementation.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions