Skip to content

fix: eliminate 'socket hang up' uncaught exceptions at the request source - #31

Open
sean-roberts wants to merge 1 commit into
mainfrom
fix-socket-hangup-source
Open

fix: eliminate 'socket hang up' uncaught exceptions at the request source#31
sean-roberts wants to merge 1 commit into
mainfrom
fix-socket-hangup-source

Conversation

@sean-roberts

Copy link
Copy Markdown
Collaborator

Problem

After PR #29, socket hang up errors persist on the dashboard (~2k/hr). Diagnosis from Datadog:

  • The process-guards are live and catching the promise-based resets — 17,789 transient network rejection swallowed in 2 days.
  • But the persisting errors are Invoke Error socket hang up — an uncaughtException from a socket 'error' on a legacy-http request (node:_http_client). The Lambda/Netlify runtime logs that itself, independent of our process uncaughtException handler, so the handler can't suppress it (the platform-override fragility we flagged).

Fix

http-guard.ts patches http/https .request/.get to attach a default 'error' listener to every outbound request → a socket reset is handled and never becomes uncaught. Self-installs on import; imported first in mcp.ts/oauth-server.ts so it's in place before any dependency captures a reference. Node-only.

Also: dropped the process-guard swallow logs warndebug (they were ~17k/2d of unactionable noise now that the guard handles most at the request).

Verify

  • 71/71 tests pass (4 new for the guard), typecheck clean.
  • Post-deploy: confirm Invoke Error socket hang up count drops.

Note

Some of these logs have a blank function_name; if any originate in the platform's own outbound calls (not our deps), the guard won't reach those — those would need a dashboard exclusion / a note to Netlify.

🤖 Generated with Claude Code

…urce

The process-guards fix (PR #29) catches the promise-based resets (swallowed as
warns) but the persisting 'Invoke Error socket hang up' errors are a different
path: an uncaughtException from a socket 'error' on a legacy-http request
(node:_http_client) that some dependency never handles. The Lambda/Netlify
runtime logs that itself, independent of our process-level uncaughtException
handler — so the handler can't suppress it.

Fix at the source instead: http-guard.ts patches http/https .request/.get to
attach a default 'error' listener to every outbound request, so a socket reset
is handled and never becomes uncaught. Self-installs on import; imported FIRST in
mcp.ts and oauth-server.ts so it patches before any dependency captures a
reference. Node-only, never edge.

Also drop the process-guard swallow logs from warn to debug — they were adding
~17k/2d of unactionable warns now that the http-guard handles most at the request.

71/71 tests pass; typecheck clean.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@netlify

netlify Bot commented Aug 13, 2026

Copy link
Copy Markdown

Deploy Preview for ntl-mcp ready!

Name Link
🔨 Latest commit 0cbdf42
🔍 Latest deploy log https://app.netlify.com/projects/ntl-mcp/deploys/6a7e04b83cb04600089278b3
😎 Deploy Preview https://deploy-preview-31--ntl-mcp.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify

netlify Bot commented Aug 13, 2026

Copy link
Copy Markdown

Deploy Preview for netlify-mcp ready!

Name Link
🔨 Latest commit 0cbdf42
🔍 Latest deploy log https://app.netlify.com/projects/netlify-mcp/deploys/6a7e04b896b0650008d63b21
😎 Deploy Preview https://deploy-preview-31--netlify-mcp.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify

netlify Bot commented Aug 13, 2026

Copy link
Copy Markdown

Deploy Preview for mcp ready!

Name Link
🔨 Latest commit 0cbdf42
🔍 Latest deploy log https://app.netlify.com/projects/mcp/deploys/6a7e04b89874910008fbe1d1
😎 Deploy Preview https://deploy-preview-31--mcp.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@coderabbitai

coderabbitai Bot commented Aug 13, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 3d5c5530-ea6f-412d-87dc-973ff47d46f2

📥 Commits

Reviewing files that changed from the base of the PR and between afe3ec4 and 0cbdf42.

📒 Files selected for processing (5)
  • netlify/functions/mcp-server/http-guard.test.ts
  • netlify/functions/mcp-server/http-guard.ts
  • netlify/functions/mcp-server/process-guards.ts
  • netlify/functions/mcp.ts
  • netlify/functions/oauth-server.ts
🔗 Linked repositories identified

CodeRabbit considers these linked repositories for cross-repo context during reviews:

  • netlify/blueprints (manual)

📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes

    • Improved handling of transient outbound network errors to prevent unnecessary warnings and disruptions.
    • Added safeguards so HTTP request failures are handled without interrupting function startup or request processing.
    • Preserved logging for unexpected network errors with useful diagnostic details.
  • Tests

    • Added coverage verifying error handling for both HTTP and HTTPS outbound requests.

Walkthrough

The pull request adds an import-time guard for outbound http and https requests. The guard attaches error listeners, suppresses transient network errors, and logs other failures. The MCP and OAuth entry points load the guard before dependent modules. Process-level transient network errors now use debug logging. Tests cover HTTP and HTTPS requests.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Mergeability Score: ⚪ Minimal · up to 0cbdf

This localized change adds request-level handling for socket errors and reduces unactionable guard logging; no actionable merge-blocking risk remains after normal checks and review.

Possibly related PRs

  • netlify/netlify-mcp#29: Both changes update process guards and initialize guards in the MCP and OAuth entry points. PR #29 focuses on process-level transient-error handling, while this PR adds request-level HTTP guarding.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the primary fix for uncaught socket hang-up exceptions at their HTTP request source.
Description check ✅ Passed The description explains the socket hang-up problem, the HTTP guard fix, logging change, validation, and deployment considerations.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-socket-hangup-source

Comment @coderabbitai help to get the list of available commands.

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