Skip to content

fix(ws): surface HTTP status/body on relay dial failure - #134

Merged
blue4209211 merged 3 commits into
mainfrom
fix/ws-dial-error-diagnostics
Aug 25, 2026
Merged

fix(ws): surface HTTP status/body on relay dial failure#134
blue4209211 merged 3 commits into
mainfrom
fix/ws-dial-error-diagnostics

Conversation

@PrashantBtkl

@PrashantBtkl PrashantBtkl commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Description

On an EC2 host, forager logged repeated dial failed: websocket: bad handshake for ~30 minutes during a relay-side connectivity issue, with no way to tell whether the relay was down, rejecting auth, or rate limiting.

gorilla/websocket returns the HTTP response alongside ErrBadHandshake, 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=502 vs status=401 vs status=429 instead of an opaque error.

Fixes # (issue)

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Enhancement (non-breaking change which improves existing functionality)
  • Refactor (non-breaking change which improves code structure)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation
  • CI/CD

How Has This Been Tested?

  • Unit tests
  • Manual testing

Checklist

  • CLA signed (the CLA bot will prompt on your first PR)
  • make validate passes (fmt + lint + test)
  • Docs updated if the wire shape, config surface, or proxy module behavior changed

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.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread pkg/ws/client.go
PrashantBtkl and others added 2 commits August 25, 2026 14:02
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
@blue4209211

Copy link
Copy Markdown
Contributor

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
blue4209211 merged commit dca7b9d into main Aug 25, 2026
6 checks passed
@blue4209211
blue4209211 deleted the fix/ws-dial-error-diagnostics branch August 25, 2026 09:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants