{{ message }}
Repository navigation
Conversation
Contributor
|
Since last review: 2 resolved, 0 still open, 0 new. Not re-run: api-compat, compat-flags, jsg-gc, kj-style, memory-safety, rust-first (no author changes in their files since the last review) Reviewed commit: 8fe074be · github run |
danlapid
force-pushed
the
dlapid/ucc-weak-handles
branch
from
October 19, 2026 03:08
18c2a81 to
23a4c38
Compare
jasnell
approved these changes
Oct 19, 2026
danlapid
force-pushed
the
dlapid/ucc-weak-handles
branch
from
October 19, 2026 07:24
23a4c38 to
64e7425
Compare
danlapid
force-pushed
the
dlapid/ucc-weak-handles
branch
2 times, most recently
from
October 20, 2026 06:02
3b980ea to
ca7a09a
Compare
jtolio
reviewed
Oct 20, 2026
jtolio
reviewed
Oct 20, 2026
jtolio
reviewed
Oct 20, 2026
jtolio
reviewed
Oct 20, 2026
jtolio
approved these changes
Oct 20, 2026
danlapid
force-pushed
the
dlapid/ucc-weak-handles
branch
from
October 20, 2026 23:13
ca7a09a to
6223b40
Compare
Convert continuation captures of `this` and of references to existing weak handles, dereferenced with KJ_REQUIRE_NONNULL where they are used: IoContext::getWeakRef(), JSG_THIS_WEAK, kj::Pin addWeak(), kj::Rc downgrade(), and addWeakToThis() on classes that are already kj::PtrTarget or kj::Refcounted. A continuation that outlives its referent now throws instead of touching freed memory; otherwise nothing changes. Also document the caller-keeps-the-buffer-alive contract on WritableStreamSink::write() and DatagramChannel::send(), and add the //src/workerd/util dependency and weak-refs.h includes that later commits use. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Changes with no behaviour change that need some focus to review: - Add workerd::WeakOwner<T>, a heap box whose kj::Weak handles go null before its value is destroyed, with tests. - Add kj::PtrTarget bases and addWeak() accessors to objects that continuations refer to (OutputGate, ActorCacheInterface, IoContext_IncomingRequest, ActorCache's list streams, ChannelTokenHandler, StoredExternalHandler, queue consumers, WorkerEntrypoint, JsRpcTargetBase, CapnpServer, and others), and convert those continuations' captures to the new handles, dereferenced with KJ_REQUIRE_NONNULL at the use. PtrTarget makes these classes non-movable; none of them is moved. - Pass sendAutoResponse() a kj::WeakRc<kj::WebSocket> instead of a reference; the caller already holds a kj::Rc. - ActorCache: move flushImpl()'s post-RPC continuations into finishFlush() and finishFlushDeleteAll(). - html-rewriter: fold the evalLater() + wait() into waitForThunk() and waitForReplacerThunk(), so the chain is consumed in the frame that creates it. Evaluation order is unchanged. - workerd-unsafe-continuation-capture: treat as safe what the KJ style guide guarantees (reference, pointer and view parameters captured by the promise their function returns), static storage, chains consumed in the same frame (result-owning sinks, local TaskSets awaited via onEmpty(), Timer::timeoutAfter, Canceler::wrap), PromiseCache factories, and SuspendableRequest url/headers owned by the returned HttpService. Recognize kj::Weak, kj::WeakRc, workerd::WeakRef and AtomicWeakRef as owning captures. Document the safe patterns in async-patterns.md, and run the check's fixture in CI against its annotations. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
danlapid
force-pushed
the
dlapid/ucc-weak-handles
branch
from
October 21, 2026 15:41
6223b40 to
8fe074b
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Captures in continuations that held bare references or this now hold weak handles, dereferenced with KJ_REQUIRE_NONNULL where they are used, so a use-after-free becomes an exception.
Owners, destruction points and lifetimes are unchanged.
Commit 1 converts captures through accessors that already exist.
Commit 2 adds workerd::WeakOwner, new PtrTarget bases and accessors with the captures that use them, and teaches workerd-unsafe-continuation-capture the KJ parameter-lifetime contract from the style guide.
The check is not enabled everywhere yet.
Co-Authored-By: Claude Opus 5.5 noreply@anthropic.com