rticommunity / rticonnextdds-connector-js

RTI Connector for Connext DDS is a lightweight technology that enables DDS data to be accessed with JavaScript.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

V8 error when running Connector in a NodeJS worker thread

WRidder opened this issue · comments

Issue

In our application we use a number of worker threads to handle certain services. One of them should run the DDS interface. We notice that when running the connector from a worker thread, a V8 error pops up, which seems related to ffi. This error does not pop up when running the rti connector sample code from the main thread.

Code

Main thread

console.log(`[Operator] About to start DDS worker ${__dirname}/worker/${ddsWorkerFile}`);
this.ddsWorker = new Worker(`${__dirname}/worker/${ddsWorkerFile}`, {
   workerData,
});

Import script

const path = require("path");
require(path.resolve(__dirname, "./dds-worker.ts"));

Worker

const { isMainThread, parentPort, workerData } = require("worker_threads");

const sleep = require('sleep')
const path = require('path')
const rti = require('rticonnextdds-connector')
const configFile = path.join(process.cwd(), '/../../dds/ShapeExample.xml')
console.log("[DDS worker] Init!", configFile);

const run = async () => {
  const connector = new rti.Connector('MyParticipantLibrary::MyPubParticipant', configFile)
  const output = connector.getOutput('MyPublisher::MySquareWriter')
  try {
    console.log('Waiting for subscriptions...')
    await output.waitForSubscriptions()

    console.log('Writing...')
    for (let i = 0; i < 500; i++) {
      output.instance.setNumber('x', i)
      output.instance.setNumber('y', i * 2)
      output.instance.setNumber('shapesize', 30)
      output.instance.setString('color', 'BLUE')
      output.write()

      sleep.msleep(50)
    }

    console.log('Exiting...')
    // Wait for all subscriptions to receive the data before exiting
    await output.wait()
  } catch (err) {
    console.log('Error encountered: ' + err)
  }
  connector.close()
}

if (!isMainThread) {
  try {
    console.log("[DDS worker] Starting...");
    run();
  } catch (e) {
    console.error(e);
    setTimeout(() => {
      console.log("[DDS worker] Shutting down..");
    }, 500);
  }
}

Error

[DDS worker] Init! D:\Github\amr-simulator\dds\ShapeExample.xml
FATAL ERROR: HandleScope::HandleScope Entering the V8 API without proper locking in place
 1: 00007FF7185BF43A v8::internal::GCIdleTimeHandler::GCIdleTimeHandler+4618
 2: 00007FF71856D186 uv_loop_fork+86646
 3: 00007FF71856DC4D uv_loop_fork+89405
 4: 00007FF7189987D7 v8::HandleScope::Initialize+103
 5: 00007FF7185E2EA9 node::CallbackScope::~CallbackScope+217
 6: 00007FF7185E3209 node::CallbackScope::~CallbackScope+1081
 7: 00007FF7185E36B6 node::MakeCallback+150
 8: 00007FFCAC3C1640 Nan::Callback::Call+368 [d:\github\amr-simulator\src\backend\node_modules\nan\nan.h]:L1746
 9: 00007FFCAC3C4440 FFI::FinishAsyncFFICall+256 [d:\github\amr-simulator\src\backend\node_modules\ffi\src\ffi.cc]:L370
10: 00007FF718612E50 uv_timer_set_repeat+1824
11: 00007FF718612DC7 uv_timer_set_repeat+1687
12: 00007FF71860E294 uv_dlerror+2452
13: 00007FF71860F068 uv_run+232
14: 00007FF71859A381 node::Init+2097
15: 00007FF71859AB57 node::Start+1159
16: 00007FF7190F408C v8::internal::AsmJsScanner::IsNumberStart+127292
17: 00007FFCB25C7034 BaseThreadInitThunk+20
18: 00007FFCB2DBD241 RtlUserThreadStart+33

System

OS: Windows 20H2 (OS Build 19042.804)
Node version: v11.15.0
Connector: "rticonnextdds-connector": "^1.0.0"

Related

Installing rticonnextdds-connector-js from the develop branch shows that in the (upcoming?) release the issue seems to be fixed. It seems to be fixed in node-ffi-napi here: node-ffi-napi/node-ffi-napi#50. However, I did need to use node version 12.13.0 instead of 11.15.0 to get it to work.

commented

This should now be resolved in release 1.1.0, where support for node v12 is added.