{"record":{"id":"fc054f85a806f55f","repo":"grafana/k6","slug":"context-is-done-before-all-s-events-were-proces","errorCode":null,"errorMessage":"context is done before all '%s' events were processed","messagePattern":"context is done before all '(.+?)' events were processed","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/event/system.go","lineNumber":117,"sourceCode":"\t}\n\n\ts.logger.WithFields(logrus.Fields{\n\t\t\"subscribers\": totalSubs,\n\t\t\"event\":       event.Type,\n\t}).Trace(\"Emitted event\")\n\n\treturn func(ctx context.Context) error {\n\t\tvar doneCount int\n\t\tfor {\n\t\t\tif doneCount == totalSubs {\n\t\t\t\tclose(doneCh)\n\t\t\t\treturn nil\n\t\t\t}\n\t\t\tselect {\n\t\t\tcase <-doneCh:\n\t\t\t\tdoneCount++\n\t\t\tcase <-ctx.Done():\n\t\t\t\treturn fmt.Errorf(\"context is done before all '%s' events were processed\", event.Type)\n\t\t\t}\n\t\t}\n\t}\n}\n\n// Unsubscribe closes the Event channel and removes the subscription with ID\n// subID.\nfunc (s *System) Unsubscribe(subID uint64) {\n\ts.subMx.Lock()\n\tdefer s.subMx.Unlock()\n\tvar seen bool\n\tfor _, sub := range s.subscribers {\n\t\tif evtCh, ok := sub[subID]; ok {\n\t\t\tif !seen {\n\t\t\t\tclose(evtCh)\n\t\t\t}\n\t\t\tdelete(sub, subID)\n\t\t\tseen = true","sourceCodeStart":99,"sourceCodeEnd":135,"githubUrl":"https://github.com/grafana/k6/blob/01ffac6f245854c1b8adc6a69857c76a15f90022/internal/event/system.go#L99-L135","documentation":"The wait-closure returned by System.Emit gives up: the context was cancelled/timed out while waiting for all subscribers of this event type to finish processing. Means a subscriber was too slow or the surrounding run was aborted mid-event.","triggerScenarios":"Thrown at internal/event/system.go:117 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Increase the timeout on the context passed to the wait function","Make event subscribers faster or non-blocking","Check whether the test run was aborted (ctrl-c, signal) which cancels the context by design"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"01ffac6f245854c1b8adc6a69857c76a15f90022","analyzedAt":"2026-08-18T03:05:52.393Z","contentChangedAt":"2026-08-18T03:05:52.393Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}