FATAL ERROR: v8::FromJust Maybe value is Nothing
See original GitHub issueAfter upgrading newrelic from latest 8.x to 9.7.4 we are getting unexpected application crashes when running newrelic inside a worker_thread.
I was able to track down a little bit more and it reproduces on 9.1.0 but works fine on 9.0.0
Description
Getting unexpected crashes with the following call stack:
FATAL ERROR: v8::FromJust Maybe value is Nothing. 1: 0xb17ec0 node::Abort() [node] 2: 0xa341f4 node::FatalError(char const*, char const*) [node] 3: 0xcfe46a v8::Utils::ReportApiFailure(char const*, char const*) [node] 4: 0xb1bb1d node::fs::FileHandle::CloseReq::Resolve() [node] 5: 0xb1bc79 [node] 6: 0x158ab2d [node] 7: 0x158f186 [node] 8: 0x15a1f15 [node] 9: 0x158fab8 uv_run [node] 10: 0xa59f25 node::SpinEventLoop(node::Environment*) [node] 11: 0xbdd23a node::worker::Worker::Run() [node] 12: 0xbdd9c8 [node] 13: 0x7f0b450e2b43 [/lib/x86_64-linux-gnu/libc.so.6] 14: 0x7f0b45174a00 [/lib/x86_64-linux-gnu/libc.so.6] Aborted (core dumped)
This one is also being triggered:
FATAL ERROR: v8::ToLocalChecked Empty MaybeLocal. 1: 0xb17ec0 node::Abort() [node] 2: 0xa341f4 node::FatalError(char const*, char const*) [node] 3: 0xcfe46a v8::Utils::ReportApiFailure(char const*, char const*) [node] 4: 0xb12f19 node::fs::FSReqPromise<node::AliasedBufferBase<double, v8::Float64Array, void> >::SetReturnValue(v8::FunctionCallbackInfov8::Value const&) [node] 5: 0xb240ca [node] 6: 0xd655cb [node] 7: 0xd66a6c [node] 8: 0xd670e6 v8::internal::Builtin_HandleApiCall(int, unsigned long*, v8::internal::Isolate*) [node] 9: 0x16148d9 [node] Aborted (core dumped)
Expected Behavior
It should be working fine as on 8.x version
Steps to Reproduce
I isolated the problem just by spawning a thread in loop that just calls newrelic and returns a simple result. The code crashes with latest 9.7.4 after some time whereas works fine with latest 8.x
The code uses https://github.com/andywer/threads.js/ to spawn the thread, but it’s using native nodeJS workers under the hood.
main.js
const newrelic = require('newrelic');
const {spawn, Thread, Worker } = require('threads');
launchChildThread = async function() {
while (true) {
const thread = await spawn(new Worker('./worker'));
try {
newrelic.incrementMetric('triggers', 1);
const result = await thread.doStuff();
console.log(`received success: ${result.success}`)
} finally {
await Thread.terminate(thread);
}
}
}
launchChildThread();
worker.js
const newrelic = require('newrelic');
const { expose } = require('threads');
expose({
async doStuff() {
console.log('worker:doStuff');
newrelic.startBackgroundTransaction('background transaction');
await new Promise(resolve => setTimeout(resolve, 1000));
newrelic.incrementMetric('executions', 1);
return {success: true};
}
});
Your Environment
- NodeJS 16 / NodeJS 18
- Ubuntu 20.04
- Alpine Linux (node:16 image)
Additional context
I tried to call shutdown() method from newrelic in the worker thread before return statement, but it doesn’t seem to have any effect.
I suspect the problem is happening when calling Thread.terminate as the last printed logs are from there, but it’s crashing the main process. I suspect there may be something pending to flush from newrelic while releasing the memory.
Issue Analytics
- State:
- Created 9 months ago
- Comments:10 (5 by maintainers)
@juanjoseruiz I had this running overnight and 0 crashes. So I suspect this should fix your issue
@juanjoseruiz the fix I’m describing hasn’t been released yet. It will be out in 9.7.5 but I plan on starting there to see if a fix exists