jest: [Bug]: Getting SIGSEGV while running Jest test(s)

Version

29.2.6

Steps to reproduce

I cannot share my code but I have about 170 test cases in over 12 test suites in my project. For months I was able to run them all together and I needed separately for each suite.

Since 2 weeks I am getting a SIGSEGV segfault error at some point. Before this, all tests were running fine. After the first occurence of the SIGSEGV, it comes up every time again. After rebooting my system, the issue seems to be gone but it will come back a few minutes or hours later.

I ran the tests for months with the command: “jest --runInBand --forceExit”. For testing, I removed the two options and also tried to use “–detectOpenHandles” or “–maxWorkers=x”. Unfortunately nothing helped.

Expected behavior

An error like a SIGSEGV should never happen in an environment like this. Whatever the issue is caused by should throw a normal error that can be handled through the framework. There is no possibility to detect the cause of this issue.

Actual behavior

PID 14705 received SIGSEGV for address: 0x0
0   segfault-handler.node               0x0000000107e6d304 _ZL16segfault_handleriP9__siginfoPv + 288
1   libsystem_platform.dylib            0x00000001ac1f32a4 _sigtramp + 56
2   node                                0x0000000102a052b0 _ZN4node6loaderL23ImportModuleDynamicallyEN2v85LocalINS1_7ContextEEENS2_INS1_4DataEEENS2_INS1_5ValueEEENS2_INS1_6StringEEENS2_INS1_10FixedArrayEEE + 232
3   node                                0x0000000102cec4bc _ZN2v88internal7Isolate38RunHostImportModuleDynamicallyCallbackENS0_11MaybeHandleINS0_6ScriptEEENS0_6HandleINS0_6ObjectEEENS2_IS6_EE + 504
4   node                                0x00000001030f3164 _ZN2v88internal25Runtime_DynamicImportCallEiPmPNS0_7IsolateE + 272
5   node                                0x000000010347f524 Builtins_CEntry_Return1_DontSaveFPRegs_ArgvInRegister_NoBuiltinExit + 100
6   node                                0x000000010352449c Builtins_CallRuntimeHandler + 92
7   node                                0x00000001033fc064 Builtins_InterpreterEntryTrampoline + 260
8   node                                0x00000001033fc064 Builtins_InterpreterEntryTrampoline + 260
9   node                                0x00000001034d1324 Builtins_PromiseConstructor + 2308
10  node                                0x00000001033f9914 Builtins_JSBuiltinsConstructStub + 340
11  node                                0x0000000103524e7c Builtins_ConstructHandler + 668
12  node                                0x00000001033fc064 Builtins_InterpreterEntryTrampoline + 260
13  node                                0x00000001033fc064 Builtins_InterpreterEntryTrampoline + 260
14  node                                0x00000001033fc064 Builtins_InterpreterEntryTrampoline + 260
15  node                                0x0000000103496f0c Builtins_ArrayForEach + 876
16  node                                0x00000001033fc064 Builtins_InterpreterEntryTrampoline + 260
17  node                                0x00000001033fc064 Builtins_InterpreterEntryTrampoline + 260
18  node                                0x00000001033fc064 Builtins_InterpreterEntryTrampoline + 260
19  node                                0x00000001034328b4 Builtins_AsyncFunctionAwaitResolveClosure + 84
20  node                                0x00000001034d2e38 Builtins_PromiseFulfillReactionJob + 56
21  node                                0x0000000103422834 Builtins_RunMicrotasks + 596
22  node                                0x00000001033fa3c4 Builtins_JSRunMicrotasksEntry + 164
23  node                                0x0000000102ccf530 _ZN2v88internal12_GLOBAL__N_16InvokeEPNS0_7IsolateERKNS1_12InvokeParamsE + 2656
24  node                                0x0000000102ccfa20 _ZN2v88internal12_GLOBAL__N_118InvokeWithTryCatchEPNS0_7IsolateERKNS1_12InvokeParamsE + 88
25  node                                0x0000000102ccfbfc _ZN2v88internal9Execution16TryRunMicrotasksEPNS0_7IsolateEPNS0_14MicrotaskQueueE + 64
26  node                                0x0000000102cf7b74 _ZN2v88internal14MicrotaskQueue13RunMicrotasksEPNS0_7IsolateE + 332
27  node                                0x0000000102cf8410 _ZN2v88internal14MicrotaskQueue17PerformCheckpointEPNS_7IsolateE + 124
28  node                                0x0000000102c0217c _ZN2v88internal12_GLOBAL__N_119HandleApiCallHelperILb0EEENS0_11MaybeHandleINS0_6ObjectEEEPNS0_7IsolateENS0_6HandleINS0_10HeapObjectEEENS8_INS0_20FunctionTemplateInfoEEENS8_IS4_EEPmi + 720
29  node                                0x0000000102c018ec _ZN2v88internal21Builtin_HandleApiCallEiPmPNS0_7IsolateE + 212

Additional context

I installed the “segfault-handler” package to my project, which will log the stack trace to a log file. This gives me some extra output:


at lib/test/test.helper.service.ts:153:21
      at $.getWebSocketClass (eval at oo_oo (fee/fee.service.spec.ts:1015:51), <anonymous>:1:2306)
      at eval (eval at oo_oo (fee/fee.service.spec.ts:1015:51), <anonymous>:1:2846)
      at $._connectToHost (eval at oo_oo (fee/fee.service.spec.ts:1015:51), <anonymous>:1:2764)
      at $.send (eval at oo_oo (fee/fee.service.spec.ts:1015:51), <anonymous>:1:4613)
      at eval (eval at oo_oo (fee/fee.service.spec.ts:1015:51), <anonymous>:1:9059)
          at Array.forEach (<anonymous>)
      at eval (eval at oo_oo (fee/fee.service.spec.ts:1015:51), <anonymous>:1:9047)
      at console.eval [as log] (eval at oo_oo (fee/fee.service.spec.ts:1015:51), <anonymous>:1:10447)
      at Object.<anonymous> (fee/fee.service.spec.ts:303:51)

I wonder, why something like “$.send” and “$._connectToHost” appears here. I have not set up any remote connection to any system. I was thinking about if the issue has something to do with the event-emitter I am using? The project heavily uses events which are emitted whole over the system, also during the tests. Or has it something to do with console.log? Line 303 which is shown in this stack trace only contains a console log with a simple hardcoded string value.

Environment

System: 
    OS: Mac OS Ventura 13.1
    CPU: Apple M1 Pro, 10 cores

Binaries: 
    Node: 19.4.0
    Yarn: 1.22.19
    npm: 9.2.0

npmPackages:
"@faker-js/faker": "^7.6.0",
"@nestjs/apollo": "^10.1.7",
"@nestjs/common": "^9.2.1",
"@nestjs/config": "^2.2.0",
"@nestjs/core": "^9.2.1",
"@nestjs/event-emitter": "^1.3.1",
"@nestjs/graphql": "^10.1.7",
"@nestjs/platform-express": "^9.2.1",
"@nestjs/schedule": "^2.1.0",
"@nestjs/swagger": "^6.1.4",
"@nestjs/throttler": "^4.0.0",
"@nestjs/typeorm": "^9.0.1",
"@types/pdfkit": "^0.12.8",
"@types/sharp": "^0.31.1",
"adm-zip": "^0.5.10",
"apollo-server-express": "^3.11.1",
"axios": "^1.2.3",
"bcrypt": "^5.1.0",
"class-transformer": "^0.5.1",
"class-validator": "^0.14.0",
"crc": "^4.3.1",
"cross-env": "^7.0.3",
"express": "^4.18.2",
"graphql": "^16.6.0",
"joi": "^17.7.0",
"jsonwebtoken": "^9.0.0",
"lodash": "^4.17.21",
"mime-types": "^2.1.35",
"moment": "^2.29.4",
"nestjs-spelunker": "^1.1.3",
"npm-check-updates": "^16.6.2",
"otpauth": "^9.0.2",
"path": "^0.12.7",
"pdfkit": "^0.13.0",
"pg": "^8.8.0",
"randomstring": "^1.2.3",
"reflect-metadata": "^0.1.13",
"rimraf": "^4.1.1",
"rxjs": "^7.8.0",
"segfault-handler": "^1.3.0",
"sharp": "^0.31.3",
"tslib": "^2.4.1",
"twilio": "^3.84.1",
"typeorm": "^0.3.11",
"uuid": "^9.0.0"

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 3
  • Comments: 15 (2 by maintainers)

Most upvoted comments

This is what I’ve found out too after I opened this issue.

I replaced all “console.log” occurrences with “console.debug” and everything worked fine and as expected.

This is totally strange for me and I cannot understand how this happens. If console.log does soething different, I expect that a Jest test will never crash with a SIGSEGV like this.

@brandwork-jb Console Ninja (when not paused) is patching your locally installed Jest node module to integrate with Jest. So if the project is opened in VS Code with Console Ninja running, external terminal running for the same project folder will use the patched version too. Try installing the latest Console Ninja version and just in case run Jest jest --clearCache command to eliminate any caching issues, and the issue should be fixed for you.

This also started happening in my nestjs project with jest. It seems adding any console log in my app code causes this error. Console log from the tests themselved seems fine.