Repository navigation
fix: harden egress proxy error handling - #23
Merged
Merged
Conversation
Catch writeHead failures and rejected resolver promises on the HTTP and CONNECT paths so a bad upstream response or lookup fails that connection with 502 instead of leaving an unhandled exception. Co-authored-by: Jake Barnby <[email protected]>
CI installs Bun latest, which accepts a UTF-8 reason phrase the Dockerfile version rejects. Drive the writer-reject cases with a control byte the client parser keeps and writeHead still refuses. Co-authored-by: Jake Barnby <[email protected]>
Docker Image Stats
Screenshot benchmark: Average of 3 runs on https://appwrite.io |
Member
Author
|
@hansi-codes review |
🟢 Tier S · Ready to mergeThe egress proxy now converts resolver failures and rejected upstream HTTP responses into controlled gateway failures, and handles stream/socket errors without letting request-handler exceptions escape. Unit tests exercise HTTP forwarding, malformed upstream status values, resolver failures, continued service, and CONNECT tunneling and refusal cases.
📂 Walkthrough · 2
Reviewed |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The egress forward proxy forwarded upstream status lines and headers through
res.writeHeadwith no error handling. Under Bun, the HTTP client parser accepts some status codes and reason phrases that the server-side writer then rejects (for example a status code below 100, or a non-ASCII reason phrase). That throw escaped the request callback and ended the process.The same handlers
awaitthe host resolver. A rejected lookup became an unhandled rejection on both the plain-HTTP and CONNECT paths.This change fails the affected connection instead: HTTP clients get 502 (or the socket is destroyed if headers were already sent), and CONNECT clients get 502 or a destroyed socket. An error listener is also attached to the upstream response stream.
Tests
Unit tests drive
startEgressGuardthrough a local raw upstream and cover:Verified locally with Bun 1.3.2 (the Dockerfile version):
bun run lint,bun run check,bun run type-check, andbun test tests/unit.