{"record":{"id":"b5f94d5cb28eae14","repo":"grafana/k6","slug":"running-on-task-queue-w","errorCode":null,"errorMessage":"running on task queue: %w","messagePattern":"running on task queue: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"internal/js/modules/k6/browser/browser/helpers.go","lineNumber":129,"sourceCode":"\tfn func() (T, error),\n) (future func() (T, error)) {\n\tvar (\n\t\tresult T\n\t\terr    error\n\t\tdone   = make(chan struct{})\n\t)\n\ttq.Queue(func() error {\n\t\tdefer close(done)\n\t\tresult, err = fn()\n\t\treturn err\n\t})\n\treturn func() (T, error) {\n\t\tselect {\n\t\tcase <-done:\n\t\t\treturn result, err\n\t\tcase <-ctx.Done():\n\t\t\tvar zero T\n\t\t\treturn zero, fmt.Errorf(\"running on task queue: %w\", common.ContextErr(ctx))\n\t\t}\n\t}\n}\n\n// newTaskQueue returns a new [taskqueue.TaskQueue] that is closed after\n// the returned cancel function is called or when the VU's context is done.\n//\n// Do not call this function off of the event loop.\nfunc newTaskQueue(vu moduleVU) (*taskqueue.TaskQueue, context.Context, context.CancelFunc) {\n\tctx, cancel := context.WithCancel(vu.Context())\n\ttq := taskqueue.New(vu.RegisterCallback)\n\tgo func() {\n\t\t<-ctx.Done()\n\t\ttq.Close()\n\t}()\n\treturn tq, ctx, cancel\n}\n","sourceCodeStart":111,"sourceCodeEnd":147,"githubUrl":"https://github.com/grafana/k6/blob/01ffac6f245854c1b8adc6a69857c76a15f90022/internal/js/modules/k6/browser/browser/helpers.go#L111-L147","documentation":"Returned by queueTask (browser/helpers.go:129) when the VU context finishes (Canceled or DeadlineExceeded, surfaced via common.ContextErr) before a queued task ran. In the browser mapping this guards the event-loop task queue used by the regex matcher behind waitForURL, waitForNavigation({ url }), waitForRequest, waitForResponse and route, so the error means 'the iteration/test was torn down while pattern matching was still pending', not a pattern problem.","triggerScenarios":"The VU iteration ends (scenario duration/graceful stop, SIGINT abort, or an iteration timeout) while a URL-pattern wait is still pending; closing the browser context/page with a waitForNavigation-style matcher in flight; end-of-test teardown racing the task queue.","commonSituations":"Short scenarios where waitForURL/waitForResponse outlive the iteration budget; k6 graceful-stop at end-of-test producing a burst of these; over-tight iterationTimeout or per-iteration budgets in arrival-rate executors.","solutions":["Make waits finish before the iteration ends: await every browser promise and size timeout options inside the scenario duration","Raise the option timeout or reduce the wait scope so the matcher completes","During intentional teardown, treat this as expected and skip/log it instead of failing the check","Upgrade k6 — the browser module's iteration-close behavior has been stabilized over releases"],"exampleFix":"// before\nconst p = page.waitForNavigation({ url: /\\/next/ }); // not awaited, iteration ends\n// after\nconst p = page.waitForNavigation({ url: /\\/next/, timeout: 5000 });\nawait p; // completes within the iteration budget","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  const nav = page.waitForNavigation({ url: /\\/next\\/, timeout: 5000 });\n  await page.click('#go');\n  await nav;\n} catch (e) {\n  if (!String(e.message).includes('running on task queue')) throw e;\n  // iteration is being torn down; skip remaining browser work\n}","preventionTips":["Await every browser promise before the end of the default function","Keep option timeouts comfortably below the scenario/iteration budget","Treat this error as expected during graceful stop and early-return instead of failing checks","Avoid firing waitFor* matchers you never await"],"tags":["k6","k6-browser","context-cancelled","task-queue","teardown"],"backgroundTag":"context-cancelled","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"}