{"record":{"id":"62d03583a18e7dc4","repo":"grafana/k6","slug":"initializing-the-main-module-hasn-t-finished-this","errorCode":null,"errorMessage":"initializing the main module hasn't finished, this is a bug in k6 please report it","messagePattern":"initializing the main module hasn't finished, this is a bug in k6 please report it","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/bundle.go","lineNumber":372,"sourceCode":"\t\tvar err error\n\t\tresult, err = modSys.RunSourceData(b.sourceData)\n\t\treturn err\n\t}\n\n\tcall, _ := sobek.AssertFunction(vuImpl.runtime.ToValue(callback))\n\n\terr = vuImpl.eventLoop.Start(func() error {\n\t\t_, err := call(nil)\n\t\treturn err\n\t})\n\n\t<-initDone\n\n\tif err == nil {\n\t\tvar finished bool\n\t\tbi.mainModule, finished, err = result.Result()\n\t\tif !finished {\n\t\t\treturn nil, errors.New(\"initializing the main module hasn't finished, this is a bug in k6 please report it\")\n\t\t}\n\t}\n\n\tif err != nil {\n\t\tvar exception *sobek.Exception\n\t\tif errors.As(err, &exception) {\n\t\t\terr = &scriptExceptionError{inner: exception}\n\t\t}\n\t\treturn nil, err\n\t}\n\n\t// If we've already initialized the original VU init context, forbid\n\t// any subsequent VUs to open new files\n\tif vuID == 0 {\n\t\tallowOnlyOpenedFiles(b.filesystems[\"file\"])\n\t}\n\n\trt.SetRandSource(common.NewRandSource())","sourceCodeStart":354,"sourceCodeEnd":390,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/bundle.go#L354-L390","documentation":"An internal invariant guard during bundle instantiation: after the VU event loop finishes, result.Result() reports the main module's load as not finished. k6 classifies this as an engine bug and asks the user to report it — it is not a script-authoring error.","triggerScenarios":"A race in asynchronous module initialization where the module-load promise has not settled when the event loop drains; ordinary script content does not produce it.","commonSituations":"Almost never seen; can surface with remote/E SM module loading or custom native (Go) extensions that yield during init on heavily loaded machines.","solutions":["Re-run the test — transient races usually do not reproduce","If reproducible, open an issue at https://github.com/grafana/k6/issues with the script, `k6 version`, and verbose logs (`--log-output=stdout`)","Bisect the script's imports to identify which module triggers it and include that in the report"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"# Rare internal race: retry once, then report\nfor i in 1 2; do k6 run script.js && break || [ $i -eq 2 ] && { echo 'Persistent init bug — report at github.com/grafana/k6/issues with k6 version + logs' >&2; exit 1; }; done","preventionTips":["Capture `k6 version` and full logs whenever this fires so the report is actionable","Reduce async top-level work in modules (await inside functions, not at import time)","Update k6 regularly — engine races get fixed upstream"],"tags":["internal","bug","module-loading","eventloop"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}