Skip to content

Drop every second socket error that has no listener - #250

Merged
jaredwray merged 3 commits into
mainfrom
cursor/socket-error-guard-b4c3
Oct 20, 2026
Merged

jaredwray merged 3 commits into
mainfrom
cursor/socket-error-guard-b4c3

Conversation

@jaredwray

@jaredwray jaredwray commented Oct 20, 2026 •

Copy link
Copy Markdown
Owner

Please check if the PR fulfills these requirements

  • Followed the Contributing and Code of Conduct guidelines.
  • Tests for the changes have been added (for bug fixes/features) with 100% code coverage.

What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)

Bug fix. Follow-up to #249. The socket guard drops a later error that has no listener. The first error still uses Node behavior.

Why

#249 is merged. Its guard dropped a second socket error only when the message contained proxy request failed. workerd node:net emits error twice for one failed socket. The driver listens with once, so the second emit has no listener and aborts the isolate. The message is not always the proxy failure. A TLS failure or a reset can abort the isolate the same way.

The guard records each socket after its first error. A later error with no listener is dropped. The first error with no listener still throws. A later error that has a listener is still delivered. tls.TLSSocket uses the same emit.

Verification

  • pnpm test: 562 tests passed. Line coverage 100% (1439/1439).
  • The unit test checks a first listener-less error, a second proxy error, a TLS handshake error, and a later error that still has a listener.

Test audit

No test was deleted. The socket guard test was extended. One new test proves the first listener-less error still throws. The old suite did not cover that case.

Do not merge, release, or deploy this PR.

Open in Web Open in Cursor 

workerd emits a socket error twice. The message is not always the proxy failure.
A TLS failure or a reset can abort the isolate the same way.

Co-authored-by: Jared Wray <me@jaredwray.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-20T03:07:23.559871Z 751328b PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@codecov

codecov Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (63928fc) to head (48ad94c).

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #250   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           44        44           
  Lines         1723      1720    -3     
  Branches       385       386    +1     
=========================================
- Hits          1723      1720    -3     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 751328b7c6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread worker/bin-store.ts Outdated
Comment on lines 41 to 42
if (event === "error" && this.listenerCount("error") === 0) {
return false;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Suppress only errors after the first socket error

When a socket emits its first error without a listener, this branch returns false and bypasses Node's unhandled-error behavior. The Worker installs this patch globally, so unrelated sockets can lose real failures, not only workerd's duplicate emit. Record whether this socket emitted an error. Suppress the emit only when that record exists. The changed test uses listener-free emits only after one handled emit, so it does not cover this case.

AGENTS.md reference: AGENTS.md:L68-L71

Useful? React with 👍 / 👎.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The guard now records each socket after its first error. A later error with no listener is dropped. The first error with no listener still throws. A later error that has a listener is still delivered. Commit cecd702. pnpm test passed: 562 tests, line coverage 100%.

cursoragent and others added 2 commits October 20, 2026 03:09
The guard now records a socket after its first error.
A later error with no listener is dropped. The first error still throws.

Co-authored-by: Jared Wray <me@jaredwray.com>
@jaredwray
jaredwray merged commit 254b02d into main Oct 20, 2026
13 checks passed
@jaredwray
jaredwray deleted the cursor/socket-error-guard-b4c3 branch October 20, 2026 03:12
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