-
Type:
Task
-
Resolution: Duplicate
-
Priority:
Major - P3
-
None
-
Affects Version/s: None
-
Component/s: None
-
None
-
Query Integration
-
None
-
None
-
None
-
None
-
None
-
None
-
None
ModuleLoaderTest does not clean up the global MozJSScriptEngine after tests run, leaving it for static destruction during process exit. In shared library builds (SCons on 7.0), this causes a segfault during _dl_fini because libscripting_common.so which holds the globalScriptEngine static has no DT_NEEDED on libmozjs.so. The dynamic linker may finalize libmozjs.so first, destroying its internal mutexes before MozJSScriptEngine::~MozJSScriptEngine() calls JS_ShutDown().
cpp_unit_test:scripting_mozjs_test] {"t":{"$date":"2026-05-19T23:50:49.160Z"},"s":"I", "c":"TEST", "id":23069, "ctx":"main","msg":"SUCCESS - All tests in all suites passed"}
[cpp_unit_test:scripting_mozjs_test] mozilla::detail::MutexImpl::mutexLock: pthread_mutex_lock failed: Invalid argument
[cpp_unit_test:scripting_mozjs_test] {"t":{"$date":"2026-05-19T23:50:49.162Z"},"s":"F", "c":"CONTROL", "id":6384300, "ctx":"shutdown","msg":"Writing fatal message","attr":{"message":"Invalid access at address: 0\n"}}
[cpp_unit_test:scripting_mozjs_test] {"t":{"$date":"2026-05-19T23:50:49.162Z"},"s":"F", "c":"CONTROL", "id":6384300, "ctx":"shutdown","msg":"Writing fatal message","attr":{"message":"Got signal: 11 (Segmentation fault).\n"}}
[cpp_unit_test:scripting_mozjs_test] {"t":{"$date":"2026-05-19T23:50:49.173Z"},"s":"I", "c":"CONTROL", "id":31380, "ctx":"shutdown","msg":"BACKTRACE","attr":{"bt":{"backtrace":[{"a":"7FD5358B56B8","b":"7FD535679000","o":"23C6B8","s":"_ZN5mongo15printStackTraceEv","C":"mongo::printStackTrace()","s+":"38"},{"a":"7FD5358B00BA","b":"7FD535679000","o":"2370BA","s":"abruptQuitWithAddrSignal","s+":"EA"},{"a":"7FD5333A7D80","b":"7FD533395000","o":"12D80","s":"funlockfile","s+":"50"},{"a":"7FD537797F4C","b":"7FD536FE6000","o":"7B1F4C","s":"_ZN7mozilla6detail9MutexImpl4lockEv","C":"mozilla::detail::MutexImpl::lock()","s+":"3C"},{"a":"7FD5378546D6","b":"7FD536FE6000","o":"86E6D6","s":"_ZN2js25DestroyHelperThreadsStateEv","C":"js::DestroyHelperThreadsState()","s+":"46"},{"a":"7FD537861918","b":"7FD536FE6000","o":"87B918","s":"_Z11JS_ShutDownv","C":"JS_ShutDown()","s+":"18"},{"a":"7FD5384AFF4D","b":"7FD53841C000","o":"93F4D","s":"_ZN5mongo5mozjs17MozJSScriptEngineD2Ev","C":"mongo::mozjs::MozJSScriptEngine::~MozJSScriptEngine()","s+":"1D"},{"a":"7FD5384AFFF2","b":"7FD53841C000","o":"93FF2","s":"_ZN5mongo5mozjs17MozJSScriptEngineD0Ev","C":"mongo::mozjs::MozJSScriptEngine::~MozJSScriptEngine()","s+":"12"},{"a":"7FD53300B607","b":"7FD532FD1000","o":"3A607","s":"__cxa_finalize","s+":"F7"},{"a":"7FD5383FA9E7","b":"7FD5383E3000","o":"179E7","s":"__do_global_dtors_aux","s+":"27"},{"a":"7FD5383C4106","b":"7FD5383B4000","o":"10106","s":"_dl_fini","s+":"206"},{"a":"7FD53300B0CC","b":"7FD532FD1000","o":"3A0CC","s":"__run_exit_handlers","s+":"13C"},{"a":"7FD53300B200","b":"7FD532FD1000","o":"3A200","s":"exit","s+":"20"},{"a":"7FD532FF481A","b":"7FD532FD1000","o":"2381A","s":"__libc_start_main","s+":"FA"},{"a":"5620825BDD7E","b":"5620825A1000","o":"1CD7E","s":"_start","s+":"2E"}],"processInfo":{"mongodbVersion":"unknown","gitVersion":"none","compiledModules":["unknown"],"uname":{"sysname":"Linux","release":"4.18.0-80.11.2.el8_0.x86_64","version":"#1 SMP Sun Sep 15 11:24:21 UTC 2019","machine":"x86_64"},"somap":[{"b":"5620825A1000","elfType":3,"buildId":"9F1D6FADA7A00A4B"},{"b":"7FD53841C000","path":"/data/mci/da8ac04aac7dd153fac6838de52a4d9e/src/build/install/bin/../lib/libscripting.so","elfType":3,"buildId":"B9F1831B91D19CA8"},{"b":"7FD536FE6000","path":"/data/mci/da8ac04aac7dd153fac6838de52a4d9e/src/build/install/bin/../lib/libmozjs.so","elfType":3,"buildId":"21682E078CD4B2A3"},{"b":"7FD5383E3000","path":"/data/mci/da8ac04aac7dd153fac6838de52a4d9e/src/build/install/bin/../lib/libscripting_common.so","elfType":3,"buildId":"EFB17E15D132C45E"},{"b":"7FD535679000","path":"/data/mci/da8ac04aac7dd153fac6838de52a4d9e/src/build/install/bin/../lib/libbase.so","elfType":3,"buildId":"B0C54985B3E91937"},{"b":"7FD533395000","path":"/lib64/libpthread.so.0","elfType":3,"buildId":"5326B8728FA01B7149DAC943100F1405533E76CE"},{"b":"7FD532FD1000","path":"/lib64/libc.so.6","elfType":3,"buildId":"0598B7D6A05E64AE676133CF6331AF5578888AD0"},{"b":"7FD5383B4000","path":"/lib64/ld-linux-x86-64.so.2","elfType":3,"buildId":"400C6833AACE02B6D44F200706D11B370AD2A7B5"}]}}},"tags":[]}
[cpp_unit_test:scripting_mozjs_test] {"t":{"$date":"2026-05-19T23:50:49.173Z"},"s":"I", "c":"CONTROL", "id":31445, "ctx":"shutdown","msg":"Frame","attr":{"frame":{"a":"7FD5358B56B8","b":"7FD535679000","o":"23C6B8","s":"_ZN5mongo15printStackTraceEv","C":"mongo::printStackTrace()","s+":"38"}}}
[cpp_unit_test:scripting_mozjs_test] {"t":{"$date":"2026-05-19T23:50:49.173Z"},"s":"I", "c":"CONTROL", "id":31445, "ctx":"shutdown","msg":"Frame","attr":{"frame":{"a":"7FD5358B00BA","b":"7FD535679000","o":"2370BA","s":"abruptQuitWithAddrSignal","s+":"EA"}}}
[cpp_unit_test:scripting_mozjs_test] {"t":{"$date":"2026-05-19T23:50:49.173Z"},"s":"I", "c":"CONTROL", "id":31445, "ctx":"shutdown","msg":"Frame","attr":{"frame":{"a":"7FD5333A7D80","b":"7FD533395000","o":"12D80","s":"funlockfile","s+":"50"}}}
[cpp_unit_test:scripting_mozjs_test] {"t":{"$date":"2026-05-19T23:50:49.173Z"},"s":"I", "c":"CONTROL", "id":31445, "ctx":"shutdown","msg":"Frame","attr":{"frame":
While this only crashes on 7.0 (shared library builds), the missing cleanup is a bug on all branches. JSCustomAllocatorTest in the same test binary already does this correctly.
Fix: Convert ModuleLoaderTest from standalone TEST() to a TEST_F() fixture with tearDown() that calls setGlobalScriptEngine(nullptr), matching JSCustomAllocatorTest.