Skip to content

Add GET /healthz and redact bin store errors - #249

Merged
jaredwray merged 1 commit into
mainfrom
cursor/bin-store-health-b4c3
Oct 20, 2026
Merged

jaredwray merged 1 commit into
mainfrom
cursor/bin-store-health-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 and feature. GET /healthz reports bin storage. Store failures return a redacted driver error. A failed Mongo connect does not abort the Worker.

Finding

A well-formed mongodb+srv URI does not throw Invalid connection string under workerd. The driver parses it and then reaches DNS. Invalid connection string still means a second @ or another unencoded reserved character in the username or password. This PR does not change the secret and does not percent-encode it. SRV DNS works for a correct URI. No seed-list URI, Atlas Data API, or extra TCP compat flag is required.

What changed

GET /healthz is on the Node server and the Worker.

  • HTTP 200: {status:'ok', bins:{store:'mongo'|'memory', connected:true, latencyMs, uriPresent, scheme}} after a real ping (admin ping or a cheap memory read).
  • HTTP 503: {status:'error', bins:{store:'mongo', connected:false, uriPresent, scheme, error:{name, message, code}}} when the ping fails.
  • uriPresent is a boolean. scheme is mongodb or mongodb+srv. The body and the logs never include the URI, username, password, or host. Connection-string fragments are removed from the error message.
  • The ping uses a short timeout and a new client. A failed client is closed and is not kept.
  • Keyv failures log one JSON line (source: mockhttp.bin-store) with the same redaction. POST /bins includes the safe driver message.
  • 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 guard drops that second emit for every message, including a proxy failure, a TLS failure, and a reset. The first emit still reaches the driver. POST /bins then returns the app 500.

Docs: site/docs/bins.md, site/docs/how-to-deploy/cloudflare.md, and site/docs/library.md.

Verification

  • pnpm test: 561 tests passed. Line coverage 100% (1435/1435).
  • pnpm build completed on the previous commit. This follow-up changes only the socket guard and its unit test.
  • workerd, mongodb://127.0.0.1:1/mockhttp: GET /healthz is 503, then POST /bins is the app 500. The isolate does not restart.
  • workerd, well-formed mongodb+srv://...: GET /healthz is 503 and the body does not contain Invalid connection string.
  • workerd, password with a raw @: the body contains Invalid connection string and the percent-encode hint, and does not contain the password or host.

Test audit

No test was deleted or dropped. The socket guard test was rewritten: it now proves a second error is dropped for both the proxy message and a TLS handshake message, while the first emit still reaches a once listener.

Do not merge, release, or deploy this PR.

Open in Web Open in Cursor 

GET /healthz pings the bin store and returns a redacted error.
A second workerd socket error no longer restarts the isolate.

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:04:54.554434Z 6d23884 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 (234ae0e) to head (6d23884).

Additional details and impacted files
@@            Coverage Diff             @@
##              main      #249    +/-   ##
==========================================
  Coverage   100.00%   100.00%            
==========================================
  Files           41        44     +3     
  Lines         1436      1723   +287     
  Branches       296       385    +89     
==========================================
+ Hits          1436      1723   +287     

☔ 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.

@jaredwray
jaredwray merged commit cab63fe into main Oct 20, 2026
13 checks passed
@jaredwray
jaredwray deleted the cursor/bin-store-health-b4c3 branch October 20, 2026 03:01

@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: 6d23884c89

ℹ️ 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 on lines +130 to +132
// Short alphabetic tokens are substrings of words like "username".
if (/^[a-z]+$/i.test(secret) && secret.length < 8) {
return message;

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 Redact short credentials and host names

When a URI contains a short alphabetic username, password, or host, this branch leaves that value in public health responses and logs. For example, mongodb://bob:foo@mongo/db does not redact bob, foo, or mongo from a driver error. This breaks the stated rule that these values never appear.

Useful? React with 👍 / 👎.

Comment thread worker/bin-store.ts
Comment on lines +203 to +205
const reset = (store: object) => {
keyv = undefined;
openedFor = undefined;

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 Do not clear a replacement client after an old failure

With concurrent MongoDB failures, the first failure clears the cached client and a later request opens a replacement. A later failure from the old store clears that replacement because reset does not verify the active store. The next request opens another pool and leaves the replacement pool open, which can exhaust connections during an outage.

Useful? React with 👍 / 👎.

Comment thread worker/bin-store.ts
Comment on lines +154 to +157
if (typeof source.on === "function") {
source.on("error", (error) => {
noteFailure("keyv.error", uri, error, reset);
});

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 Handle forwarded store errors on the outer Keyv

When KeyvMongo emits an error outside an awaited store method, this listener logs it but Keyv's forwarding listener still throws it. The added test confirms that the original error escapes from emitError. A background network error can therefore abort the Worker isolate instead of only resetting the failed client.

Useful? React with 👍 / 👎.

@jaredwray jaredwray mentioned this pull request Oct 28, 2026
4 tasks done
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