{"record":{"id":"3799a2da74e41148","repo":"grafana/k6","slug":"fail-to-abort-request-id-s-w","errorCode":null,"errorMessage":"fail to abort request (id: %s): %w","messagePattern":"fail to abort request \\(id: (.+?)\\): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/network_manager.go","lineNumber":925,"sourceCode":"}\n\nfunc (m *NetworkManager) AbortRequest(requestID fetch.RequestID, errorReason string) error {\n\tm.logger.Debugf(\"NetworkManager:AbortRequest\", \"aborting request (id: %s, errorReason: %s)\",\n\t\trequestID, errorReason)\n\tnetErrorReason, ok := m.errorReasons[errorReason]\n\tif !ok {\n\t\treturn fmt.Errorf(\"unknown error code: %s\", errorReason)\n\t}\n\n\taction := fetch.FailRequest(requestID, netErrorReason)\n\tif err := action.Do(cdp.WithExecutor(m.ctx, m.session)); err != nil {\n\t\t// Avoid logging as error when context is canceled.\n\t\t// Most probably this happens when trying to fail a site's background request\n\t\t// while the iteration is ending and therefore the browser context is being closed.\n\t\tif errors.Is(err, context.Canceled) {\n\t\t\tm.logger.Debug(\"NetworkManager:AbortRequest\", \"context canceled interrupting request\")\n\t\t} else {\n\t\t\treturn fmt.Errorf(\"fail to abort request (id: %s): %w\", requestID, err)\n\t\t}\n\t}\n\n\treturn nil\n}\n\nfunc (m *NetworkManager) ContinueRequest(\n\trequestID fetch.RequestID,\n\topts ContinueOptions,\n\toriginalHeaders []HTTPHeader,\n) error {\n\tm.logger.Debugf(\"NetworkManager:ContinueRequest\", \"continuing request (id: %s)\", requestID)\n\taction := fetch.ContinueRequest(requestID)\n\n\tif len(opts.Headers) > 0 {\n\t\taction = action.WithHeaders(toFetchHeaders(opts.Headers))\n\t}\n\tif opts.URL != \"\" {","sourceCodeStart":907,"sourceCodeEnd":943,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/common/network_manager.go#L907-L943","documentation":"The CDP command Fetch.failRequest returned an error while trying to abort a request, and the error was not context.Canceled (which is deliberately swallowed as debug noise). The interception could not be delivered — usually because the request/target no longer exists on the browser side.","triggerScenarios":"route.abort(reason) executed after the page navigated away or the target was destroyed, so the fetch.RequestID is stale; aborting a background request (analytics, long-poll, service worker fetch) while the browser context is closing but the context wasn't canceled yet; double-handling the same route (abort twice).","commonSituations":"Aborting third-party/background requests at end-of-iteration; handlers racing page.close(); SPA sites that re-issue requests during navigation so the handler's request is already gone.","solutions":["Abort early in the handler — before any await that can let navigation proceed","Only handle each intercepted request once (abort XOR continue XOR fulfill)","If it only occurs at iteration end, it is teardown noise: stop aborting once the iteration is ending, or catch and ignore at the script level if acceptable for your assertions","Reduce the race by unroute()-ing before page.close()"],"exampleFix":"// before\npage.route('**/*', async r => {\n  await somethingSlow();\n  await r.abort('aborted'); // request may be gone by now\n});\n\n// after\npage.route('**/*', r => r.abort('aborted')); // decide and abort immediately","handlingStrategy":"try-catch","validationCode":"if (page.isClosed()) { /* skip aborting: request lifecycle already over */ }","typeGuard":null,"tryCatchPattern":"try {\n  await route.abort('aborted');\n} catch (e) {\n  if (/fail to abort request/.test(String(e))) return; // stale request; nothing to abort\n  throw e;\n}","preventionTips":["Abort immediately and synchronously in the handler — no awaits before the decision","Unroute before closing the page so pending handler work drains in order","Don't abort the same route twice"],"tags":["cdp","browser","route","abort","race-condition"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}