Skip to content

Fixed PreToolUse and Stop hook HTTP 502 errors (regression in claude-code 2.1.118) - #87

Merged
oleg68 merged 1 commit into
nbplugins:release/0.21from
oleg68:bugfix/0.21/hook
Apr 24, 2026
Merged

oleg68 merged 1 commit into
nbplugins:release/0.21from
oleg68:bugfix/0.21/hook

Conversation

@oleg68

@oleg68 oleg68 commented Apr 24, 2026

Copy link
Copy Markdown
Collaborator

Backport of #86 to release/0.21.

Summary

Two root causes for HTTP 502 on PreToolUse/Stop hooks:

  • Thread exhaustion: HookServlet blocked a Jetty thread per pending request. With multiple diff dialogs open simultaneously the thread pool was exhausted. Fixed by converting HookServlet to async Jetty API (startAsync / whenComplete).
  • IPv6 vs IPv4: Hook and MCP SSE URLs used localhost which on systems where localhost resolves to ::1 (IPv6) first causes claude-code's Bun HTTP client to connect to ::1:PORT. Jetty's ServerConnector binds to 0.0.0.0 (IPv4 only) and refuses the connection; claude-code reports this as "HTTP 502". Fixed by using 127.0.0.1 instead of localhost in all URLs written to settings.local.json.

🤖 Generated with Claude Code

…code 2.1.118)

Two root causes:

1. Hook servlet blocked a Jetty thread per pending request (user had not yet
   clicked Accept/Reject in the diff dialog). When multiple diffs were open
   simultaneously the thread pool was exhausted and subsequent requests returned
   502. Fixed by converting HookServlet to async Jetty API (startAsync /
   whenComplete) so threads are released immediately after reading the request.
   Added MCPSseServerPerSessionTest TC-5/TC-6 and test_hook_concurrent.py to
   reproduce and guard against regression.

2. Hook and MCP SSE URLs used "localhost" which on systems where localhost
   resolves to ::1 (IPv6) first causes claude-code's Bun HTTP client to connect
   to ::1:PORT. Jetty's ServerConnector binds to 0.0.0.0 (IPv4 only) and refuses
   the connection; claude-code reports the failure as "HTTP 502". Fixed by using
   127.0.0.1 instead of localhost in all hook and SSE URLs written to
   settings.local.json. Added test_hook_ipv6_localhost.py to verify.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@oleg68
oleg68 merged commit a324125 into nbplugins:release/0.21 Apr 24, 2026
3 checks passed
@oleg68
oleg68 deleted the bugfix/0.21/hook branch April 24, 2026 14:10
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.

1 participant