Skip to content

Create WebSocket revocation promises lazily - #8178

Merged
danlapid merged 2 commits into
mainfrom
dlapid/lazy-websocket-revocation
Nov 3, 2026
Merged

danlapid merged 2 commits into
mainfrom
dlapid/lazy-websocket-revocation

Conversation

@danlapid

@danlapid danlapid commented Nov 3, 2026

Copy link
Copy Markdown
Collaborator

newRevocableWebSocketWorkerInterface() forks the revocation promise when the wrapper is built, and again for every request, though the promise only matters once an event opens a WebSocket or a CONNECT tunnel. Callers whose revocation promise is costly to set up, such as one that waits on a cross-thread wait list, pay for it on every ordinary HTTP request.

This adds an overload that takes a factory for the revocation promise. The wrapper calls it at most once, when an event first opens a WebSocket or CONNECT tunnel, and shares the one forked promise among everything it opens. The existing promise overload keeps its behavior.

Tests

  • worker-interface-test: the factory is never called for ordinary responses; it is called once and shared across WebSockets; a WebSocket accepted after revocation was triggered is still revoked; a CONNECT tunnel is neutered; the eager overload still revokes. Passes with --runs_per_test=5.

Benchmark

bench-revocable-worker-interface sends an ordinary request through the wrapper, revoking through a CrossThreadWaitList (optimized build, 10 repetitions):

ns/request cv
eager promise 462 2.6%
factory 144 3.3%

🤖 Generated with Claude Code

@danlapid
danlapid requested review from a team as code owners November 3, 2026 03:19

@clanky-the-clanker clanky-the-clanker 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.

Superseded by the review of 20264adf.

This review, of b9334b8f

💬 Approved with comments — The lazy revocation logic is correct and well tested. The only issue is an optional formatting fix: one test line is longer than 100 columns.

Findings: 1 suggestion (1 is an inline comment on the diff)

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.


📋 Code Quality: 💬 1 suggestion

The lazy revocation logic is correct. One test line is longer than 100 columns.

Recommendation: 💬 Optional Nits

  • [SUGGESTION] worker-interface-test.c++:109 is 106 columns, over the 100-column limit enforced by clang-format. (src/workerd/io/worker-interface-test.c++:109)
View full review

RevokePromiseSource builds the forked promise on the first addBranch() call and switches state only after the factory returns. The reference to it held by RevocableWebSocketHttpResponse points into the interface object, and the response is attached to the request promise, so this adds no new lifetime assumption beyond the existing WorkerInterface&. The eager overload still delivers the same rejection to every branch.

One formatting nit: worker-interface-test.c++:109 is 106 columns.


✅ All other checks passed

🔒 Security: ✅ LGTM

No security issues found.


📖 AGENTS.md: ✅ LGTM

No AGENTS.md updates needed.


⚡ Performance: ✅ LGTM

No performance issues. The change cuts per-request cost for ordinary HTTP requests.


📝 Documentation: ✅ LGTM

No documentation issues found.


Reviewed commit: b9334b8f

@clanky-the-clanker clanky-the-clanker 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.

Superseded by the review of 57a88500.

This review, of 20264adf

✅ Approved — The formatting issue from the last review is fixed and no new issues were found. The lazy revocation promise is created at most once and shared correctly, and tests cover it.

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.


✅ All checks passed

🔒 Security: ✅ LGTM

No security issues found.


📖 AGENTS.md: ✅ LGTM

No AGENTS.md updates needed.


📋 Code Quality: ✅ LGTM

  • The over-long line in worker-interface-test.c++ is fixed. The lambda in makeRevokeProm() is now wrapped, and every changed C++ file stays within 100 columns.
  • RevokePromiseSource::addBranch() is correct:
    • It calls the factory at most once.
    • If the factory throws, the state stays as it was, so the next call tries again.
    • The stored function is only destroyed after the factory has returned.
  • RevocableWebSocketHttpResponse holds a reference into the interface object. The response is attached to the request promise, so this adds no lifetime assumption beyond the existing WorkerInterface&.
  • The new tests cover each behaviour the description lists: the factory is never called for ordinary responses, it is called once and shared across WebSockets, a WebSocket accepted after revocation is still revoked, a CONNECT tunnel is neutered, and the eager overload still revokes.

⚡ Performance: ✅ LGTM

No performance issues. Ordinary HTTP requests no longer pay to fork the revocation promise.


📝 Documentation: ✅ LGTM

No documentation issues found.


Reviewed commit: 20264adf

danlapid and others added 2 commits November 3, 2026 09:34
newRevocableWebSocketWorkerInterface() forks the revocation promise
when the wrapper is built, and again for every request, though the
promise only matters once an event opens a WebSocket or a CONNECT
tunnel. Callers whose revocation promise is costly to set up, such as
one that waits on a cross-thread wait list, pay for it on every
ordinary HTTP request.

Add an overload that takes a factory for the revocation promise. The
wrapper calls it at most once, when an event first opens a WebSocket
or CONNECT tunnel, and shares the one forked promise among everything
it opens. The promise overload keeps its behavior.

bench-revocable-worker-interface sends an ordinary request through
the wrapper, revoking through a CrossThreadWaitList. Optimized build,
10 repetitions:

  eager promise   462 ns/request (cv 2.6%)
  factory         144 ns/request (cv 3.3%)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@danlapid
danlapid force-pushed the dlapid/lazy-websocket-revocation branch from 20264ad to 57a8850 Compare November 3, 2026 14:34

@clanky-the-clanker clanky-the-clanker 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.

✅ Approved — The formatting issue from the last review is fixed and no new issues were found. The lazy revocation promise is created at most once and shared correctly, and tests cover it.

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.


✅ All checks passed

🔒 Security: ✅ LGTM

No security issues found.


📖 AGENTS.md: ✅ LGTM

No AGENTS.md updates needed.


📋 Code Quality: ✅ LGTM

  • The over-long line in worker-interface-test.c++ is fixed. The lambda in makeRevokeProm() is now wrapped, and every changed C++ file stays within 100 columns.
  • RevokePromiseSource::addBranch() is correct:
    • It calls the factory at most once.
    • If the factory throws, the state stays as it was, so the next call tries again.
    • The stored function is only destroyed after the factory has returned.
  • RevocableWebSocketHttpResponse holds a reference into the interface object. The response is attached to the request promise, so this adds no lifetime assumption beyond the existing WorkerInterface&.
  • The new tests cover each behaviour the description lists: the factory is never called for ordinary responses, it is called once and shared across WebSockets, a WebSocket accepted after revocation is still revoked, a CONNECT tunnel is neutered, and the eager overload still revokes.

⚡ Performance: ✅ LGTM

No performance issues. Ordinary HTTP requests no longer pay to fork the revocation promise.


📝 Documentation: ✅ LGTM

No documentation issues found.


Reviewed commit: 57a88500 — same changes as 20264adf, so this is that commit's review (no new review was run; line numbers are as of 20264adf)

@danlapid
danlapid merged commit 699687a into main Nov 3, 2026
34 of 38 checks passed
@danlapid
danlapid deleted the dlapid/lazy-websocket-revocation branch November 3, 2026 15:56
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.

3 participants