fix(ws): surface HTTP status/body on relay dial failure - #134
Merged
Conversation
Bad-handshake errors from the relay were logged as an opaque "websocket: bad handshake" with no indication of why (relay down, auth rejected, rate limited, etc.). gorilla/websocket returns the HTTP response alongside ErrBadHandshake; capture and log its status code and body instead of discarding it.
There was a problem hiding this comment.
Code Review
This pull request enhances error reporting during WebSocket connection failures by capturing and reading the HTTP response body and status code. The reviewer identified a potential nil pointer dereference panic if resp.Body is nil and provided a code suggestion to safely check resp.Body before reading or closing it.
Address review feedback: resp != nil doesn't guarantee resp.Body is non-nil, so guard the read/close to avoid a potential nil pointer dereference while still reporting the HTTP status code. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CJDCzrsi75CZNjGJZZbDkx
Contributor
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request updates the WebSocket client in pkg/ws/client.go to capture and include the HTTP response status and body (up to 1024 bytes) in the error message when a connection dial fails. I have no feedback to provide as there are no review comments.
blue4209211
approved these changes
Aug 25, 2026
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.
Description
On an EC2 host, forager logged repeated
dial failed: websocket: bad handshakefor ~30 minutes during a relay-side connectivity issue, with no way to tell whether the relay was down, rejecting auth, or rate limiting.gorilla/websocketreturns the HTTP response alongsideErrBadHandshake, but forager discarded it (conn, _, err := ...). This change captures and logs the response status code and body (truncated to 1KB) so future incidents show e.g.status=502vsstatus=401vsstatus=429instead of an opaque error.Fixes # (issue)
Type of change
How Has This Been Tested?
Checklist
make validatepasses (fmt + lint + test)