-
Notifications
You must be signed in to change notification settings - Fork 11
Document proxy error codes and the X-Kernel-Proxy-Error header #610
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+62
−1
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| --- | ||
| title: "Proxy Errors" | ||
| --- | ||
|
|
||
| When a request cannot be completed at the proxy layer, Kernel serves a branded error page and sets the `X-Kernel-Proxy-Error` response header to a typed code. | ||
|
|
||
| The header is set on every branded proxy-layer error response, including WebSocket and subresource requests where the page body never renders. The status is always `502`, including for timeouts, so use the header rather than the status to decide what went wrong. | ||
|
|
||
| ## Error codes | ||
|
|
||
| | Code | What happened | Retry | | ||
| | --- | --- | --- | | ||
| | `upstream_timeout` | Kernel's connection to the upstream proxy provider did not complete within its deadline. | Yes | | ||
| | `provider_unreachable` | The upstream proxy provider could not reach the destination. | Yes | | ||
| | `upstream_connect_failed` | The connection to the destination failed. | Yes | | ||
| | `upstream_dns_failure` | The upstream proxy host could not be resolved. | Yes | | ||
| | `origin_tls_timeout` | The proxy reached the destination, but the destination did not complete its TLS handshake in time. | Yes | | ||
| | `restricted_route_unavailable` | The destination requires a specialized egress route and Kernel could not build one. Kernel will not fall back to a provider known to reject the destination. | Yes, except on `.gov` destinations. There, create a new residential proxy with no targeting, country-only targeting, or a U.S. state, confirm it with [`POST /proxies/{id}/check`](https://kernel.sh/docs/api-reference/proxies/check-proxy-health), then use it for the session. | | ||
| | `proxy_unavailable` | A failure inside Kernel's own proxy layer, not your automation or the destination. | Yes | | ||
| | `origin_response_incomplete` | The destination closed the connection before sending a complete response. | Only if safe. The destination may have received the request, so retry only when repeating the action cannot cause duplicate changes. | | ||
| | `provider_rejected` | The upstream proxy provider rejected the request before the destination connection was established. | No. Try a different proxy or proxy type, and check the credentials on a [custom proxy](/proxies/custom). | | ||
| | `provider_blacklisted` | The upstream proxy provider blocks this destination. | No. Try a different proxy or proxy type, or disable the proxy for this destination. | | ||
| | `destination_blocked` | Kernel policy blocks connections to internal and private addresses. | No. Use a public destination address. | | ||
|
|
||
| ## Recovering from a proxy error | ||
|
|
||
| An agent driving the browser usually recovers on its own, because a failed step leads it to re-navigate. When a person is driving the browser instead — for example through an embedded [live view](/browsers/live-view) — nobody re-navigates, and a transient provider failure becomes a dead end. | ||
|
|
||
| Read the header on a `502` and retry the navigation so those failures never reach the person holding the browser: | ||
|
|
||
| ```typescript Typescript/Javascript | ||
| const RETRYABLE = new Set([ | ||
| 'upstream_timeout', | ||
| 'provider_unreachable', | ||
| 'upstream_connect_failed', | ||
| 'upstream_dns_failure', | ||
| 'origin_tls_timeout', | ||
| 'restricted_route_unavailable', | ||
| 'proxy_unavailable', | ||
| ]); | ||
|
|
||
| async function navigate(page, url, attempts = 3) { | ||
| for (let attempt = 1; ; attempt++) { | ||
| const response = await page.goto(url); | ||
| const code = response?.headers()['x-kernel-proxy-error']; | ||
|
|
||
| if (!code || !RETRYABLE.has(code) || attempt === attempts) return response; | ||
|
|
||
| await new Promise((resolve) => setTimeout(resolve, 1000 * attempt)); | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| `origin_response_incomplete` is deliberately absent from that set. The destination may have already acted on the request, so retrying it automatically can duplicate a submission. | ||
|
|
||
| ## Observing proxy errors after the fact | ||
|
|
||
| Proxy failures are also reported as `proxy_error` [browser telemetry](/browsers/telemetry/overview) events in the `network` category. Use the header to recover in the moment, and telemetry to attribute failures per session and per URL afterwards. | ||
|
|
||
| The telemetry `code` does not cover every code above. `origin_response_incomplete` is not reported as a `proxy_error` event, and a header value the browser image does not recognize is reported as `unknown`, with the original value in `raw_code`. Read the header when you need the exact code. | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gov recovery restates canonical guidance
Low Severity
The
restricted_route_unavailableretry cell restates residential.govtargeting rules and the proxy health-check procedure rather than linking to those canonical pages. The inlined check also omits a.govURL.Triggered by learned rule: Single source of truth — no deep content duplication across pages
Reviewed by Cursor Bugbot for commit 94d949e. Configure here.