Skip to content

Destroying Napi::ThreadSafeFunction instances causing segfault, but Linux only? #592

@csheely

Description

@csheely

I have Node.js code that appears to work fine on Windows but that often crashes on Linux. If I'm doing something incorrectly, I can't see it, so I'm hoping someone can assist me.

  • Windows 10, Visual Studio 2017
  • Ubuntu 18.04, gcc 7.4.0
  • NAPI_VERSION = 4
  • Node version 10.17 and 12.13 (no difference in behavior)

I've distilled my module down and posted it here for reference: https://github.com/csheely/napi-threadsafe-function. See the bottom of the README for the commands to build the module and run the test app (pretty simple).

The module exposes a Foo class that is instantiated from JavaScript code. The Foo object's registerBar() method creates and returns a BarInterface object, and a Napi::Function argument is stored as a Napi::ThreadSafeFunction in a BarActivityReceiver helper class (will be called from other threads in the "real' app when activity occurs).

When I destroy the BarActivityReceiver object, I call Napi::ThreadSafeFunction::Release() on the thread safe function member, as the documentation states.

On Linux, if I create and then destroy one or two of these objects at a time, the code runs but eventually crashes after a few minutes following the destruction of the objects.

If I create and destroy 10 objects at a time (which is what my test app does), it appears to always crash the first time, after the 10th object is destroyed. But only on Linux.

The root folder of my repo contains valgrind output from a debug build that seems to show things go awry due to the Napi::ThreadSafeFunction destructor.

Thanks in advance for any assistance you can provide!

-Chris

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions