{"record":{"id":"9ae742c235af950d","repo":"grafana/k6","slug":"109","errorCode":"109","errorMessage":"unexpected k6 panic: %s\n%s","messagePattern":"unexpected k6 panic: (.+?)\n(.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"internal/cmd/root.go","lineNumber":193,"sourceCode":"\n\treturn nil\n}\n\nfunc (c *rootCommand) execute() {\n\tctx, cancel := context.WithCancel(c.globalState.Ctx)\n\tc.globalState.Ctx = ctx\n\n\texitCode := -1\n\tdefer func() {\n\t\tcancel()\n\t\tc.stopLoggers()\n\t\tc.globalState.OSExit(exitCode)\n\t}()\n\n\tdefer func() {\n\t\tif r := recover(); r != nil {\n\t\t\texitCode = int(exitcodes.GoPanic)\n\t\t\terr := fmt.Errorf(\"unexpected k6 panic: %s\\n%s\", r, debug.Stack())\n\t\t\tif c.loggerIsRemote {\n\t\t\t\tc.globalState.FallbackLogger.Error(err)\n\t\t\t}\n\t\t\tc.globalState.Logger.Error(err)\n\t\t}\n\t}()\n\n\t// Completion requests for unregistered extensions must bypass Execute:\n\t// cobra's __complete writes to stdout as a side-effect, and the\n\t// provisioned binary's output would append to it, producing double output.\n\tvar err error\n\tif ext, ok := detectExtensionCompletion(c.cmd, c.globalState); ok {\n\t\terr = completeExtension(c.globalState, ext, newCacheProvisioner(c.globalState))\n\t} else {\n\t\tvar executed *cobra.Command\n\t\texecuted, err = c.cmd.ExecuteC()\n\t\t// Report subcommand usage after the command runs, regardless of its exit\n\t\t// error, so a failed subcommand is still counted.","sourceCodeStart":175,"sourceCodeEnd":211,"githubUrl":"https://github.com/grafana/k6/blob/8d06114777191d21ef885d05c5f8aa9e1ed838ae/internal/cmd/root.go#L175-L211","documentation":"This is k6's top-level recover() in rootCommand.execute(): an unrecovered Go panic occurred somewhere in the k6 process, and k6 caught it to print the panic value plus a full goroutine stack dump (debug.Stack()) before exiting with code 109 (exitcodes.GoPanic). The message is intentionally generic; the stack trace printed with it identifies the actual fault, and it is logged to both the normal and fallback loggers (including remote Loki logging if configured).","triggerScenarios":"Any panic escaping normal error handling during a command: a bug in k6 core, a panic in an xk6 extension module, a race in the browser/CDP module, or a nil dereference in module code reached from JavaScript. Reproduce by running the same script; the panic fires deterministically or under load.","commonSituations":"Rebuilding a binary with an xk6 extension built against a different k6 version; hitting a known panic fixed in a later k6 release; browser-module concurrency bugs; corrupted state after out-of-memory conditions.","solutions":["Read the stack trace in the output — the top k6/extension frames name the faulting component","Search or file an issue at github.com/grafana/k6/issues with the full stack trace, `k6 version` output, and a minimal reproducer script","If an xk6 extension is involved, rebuild the binary so the extension matches your k6 version (xk6 build with matching --with pins)","Try the latest k6 release; if it is a regression, pin the last known-good older version"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"# capture the panic report (exit code 109) instead of losing the stack trace\nset +e\nk6 run script.js > k6.log 2>&1\nec=$?\nset -e\nif [ \"$ec\" -eq 109 ]; then\n  echo \"k6 panicked — filing report\" >&2\n  grep -A40 'unexpected k6 panic' k6.log   # extract panic value + stack for the issue\n  exit 109\nfi","preventionTips":["Pin the k6 version in CI and rebuild xk6 extension binaries against the exact same version","Keep stderr captured to a file in every CI run so stack traces survive","Reproduce panics with --verbose and a minimal script before reporting; include `k6 version` output in issues","For long-running jobs, wrap k6 in a supervisor that records the log on non-zero exit"],"tags":["k6","panic","stack-trace","exit-code-109","internal-error"],"backgroundTag":"unexpected-panic","analyzedSha":"8d06114777191d21ef885d05c5f8aa9e1ed838ae","analyzedAt":"2026-08-18T03:05:52.393Z","contentChangedAt":"2026-08-18T03:05:52.393Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}