@@ -33,6 +33,8 @@ if (!isAsyncContextFrameAvailable()) {
3333const path = require ( 'node:path' ) ;
3434const { spawnSync } = require ( 'node:child_process' ) ;
3535
36+ const { acfFlags } = require ( './node-flags' ) ;
37+
3638const lib = require ( '..' ) ;
3739const { ThreadContext, getContext, clearContext, getProcessContextAttributes, _currentRecordBytes } = lib ;
3840
@@ -595,6 +597,23 @@ test('appendAttributes after invalidate mutates attrs_data but leaves valid=0',
595597 } ) ;
596598} ) ;
597599
600+ // Regression test: CtxWrap used to derive from node::ObjectWrap, whose
601+ // destructor calls RemoveEnvironmentCleanupHook. A CtxWrap collected during
602+ // isolate teardown hit that function's CHECK that an Environment is current
603+ // and aborted the process.
604+ test ( 'contexts collected during isolate teardown do not abort' , ( ) => {
605+ const child = path . join ( __dirname , 'teardown-child.js' ) ;
606+ const r = spawnSync ( process . execPath , [ ...acfFlags ( ) , child , '3000' ] , {
607+ encoding : 'utf8' ,
608+ } ) ;
609+ assert . equal (
610+ r . status ,
611+ 0 ,
612+ `teardown-child exited with status=${ r . status } signal=${ r . signal } \n` +
613+ `${ r . stdout } ${ r . stderr } ` ,
614+ ) ;
615+ } ) ;
616+
598617test ( 'otel_thread_ctx_nodejs_v1 is exported as a TLS dynsym' , ( t ) => {
599618 const addon = path . join ( __dirname , '..' , 'build' , 'Release' , 'customlabels.node' ) ;
600619 if ( ! require ( 'node:fs' ) . existsSync ( addon ) ) {
0 commit comments