Repository navigation
Extend startup snapshot support - #8405
Conversation
|
This pull request's reviews are posted as pull request reviews: see the review of |
|
clanky review |
There was a problem hiding this comment.
⚠️ Out of date: this review is of2e74745f; the pull request is now at8de369f4. Someone with write access can commentclanky review(orclanker reviewor@clanky-the-clanker review) to review the new commits.
💬 Approved with comments — One WARNING: Performance::snapshotClone() silently drops top-level EventTarget listeners on performance. Plus an INFO about missing tests for the new Performance clone and the pending-C++-continuation fallback.
Findings: 1 warning · 1 info (2 are inline comments on the diff)
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
🔧 Fix with your agent
Paste the following into your coding agent to investigate and fix these issues.
Fix the following code review issues found in pull request #8405.
Before making changes, review each issue and present a brief summary table:
- For each finding, state whether you agree, disagree, or need clarification
- If you disagree (e.g., the fix would require disproportionate changes
for minimal ROI, or the finding is factually incorrect), explain why
- If you need to clarify something before deciding, ask those questions
- Then share your plan for which issues to tackle and in what order
## WARNING (1)
### [Code Quality] `Performance::snapshotClone()` checks only `entries`, so listeners added to `performance` at the top level are silently dropped when the Worker starts from the snapshot.
- **File:** src/workerd/api/performance.c++:16
## INFO (1)
### [Code Quality] No test covers the pending-C++-continuation fallback registered here, or `Performance::snapshotClone()`.
- **File:** src/workerd/jsg/promise.h:457
📋 Code Quality: ⚠️ 1 warning · 1 info
Performance clone loses EventTarget listeners; the new Performance clone and pending-continuation fallback have no tests.
Recommendation: 📝 Minor Comments
- [WARNING]
Performance::snapshotClone()checks onlyentries, so listeners added toperformanceat the top level are silently dropped when the Worker starts from the snapshot. (src/workerd/api/performance.c++:16) - [INFO] No test covers the pending-C++-continuation fallback registered here, or
Performance::snapshotClone(). (src/workerd/jsg/promise.h:457)
View full review
src/workerd/api/performance.c++:16:PerformanceextendsEventTarget. Whenenable_global_performance_classesor the perf_hooks flag is on, it inheritsaddEventListenerandon*handlers (performance.h:603-604), and those handlers live inEventTarget::typeMap.snapshotClone()only checksentriesand returns a freshPerformancewith an empty handler map. The snapshot restores listeners in C++ only for the global scope (EventTarget::restoreSnapshotListener()). A listener registered onperformanceat the top level is therefore lost on load, and the Worker does not fall back to starting without a snapshot.src/workerd/jsg/promise.h:457: nothing tests the newisPreparingSnapshot()registration inthenImpl. Thecpp-streamscase deliberately has no pendingpull(). Nothing testsPerformance::snapshotClone()either, neither the clonable case nor the fallback once entries are recorded.
✅ All other checks passed
🔒 Security: ✅ LGTM
No security issues found in this change.
📖 AGENTS.md: ✅ LGTM
This pull request does not change any AGENTS.md files.
⚡ Performance: ✅ LGTM
No performance issues found.
📝 Documentation: ✅ LGTM
The updated docs/startup-snapshot.md sections match the changed code.
Reviewed commit: 2e74745f
2e74745 to
4e079a5
Compare
|
@csjh it should be ready, I've addressed all comments |
…napshot The startup snapshot no longer requires the TypeScript streams implementation. What kept C++ streams out was a stream whose pull() or start() is still pending when top-level evaluation ends: its C++ promise continuation is a v8::Function whose callback is a template instantiation the zygote's external reference table does not hold, so CreateBlob() aborted the process on the unknown address. The jsg::Promise::thenImpl now registers the two callbacks of every continuation created while a snapshot is being prepared; the serializer then reaches the continuation's opaque callback data, which has no snapshot transfer, and the zygote fails with the usual unclonable report (ReadableStreamDefaultController, OpaqueWrappable, ReadableStream), so the Worker starts without a snapshot instead of taking the process down. A C++ stream whose top level leaves no pending pull transfers like any other object.
The `performance` global is reachable from the context of any Worker whose top level touches it (reading performance.now() or importing node:perf_hooks is enough), and Performance had no snapshot transfer, so such Workers started without a snapshot. An instance that has recorded no entries and registered no listeners is rebuilt from the isolate's limit enforcer; one with entries holds jsg::Refs to PerformanceEntry objects, which a clone cannot carry, and one with listeners holds JavaScript functions, so both stay unclonable. The enforcer is the current isolate's rather than the member's: the clone is made in the zygote, stored in the shared artifact, and cloned again in every Worker started from it, where the member would be the dead zygote's enforcer. EventTarget gains hasEventListeners(). startup-snapshot-wrappables-test gains a Worker whose top level touches `performance` and one that records a mark there.
4e079a5 to
c106656
Compare
csjh
left a comment
There was a problem hiding this comment.
not sure how much we need the C++ streams support since it'll be gone before December afaik but might as well
wrappable.h declares isolateRegisterExternalReference() as an ordinary function, while setup.h defines it inline. A translation unit that sees only the declaration then refers to a symbol that no object file defines, and edgeworker's release build fails to link. Defining it in setup.c++ gives it one definition. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
it is not a support of C++ streams, this PR only supports external reference registration for C++ streams so they don't fail the whole process because V8 reacts to missing ext ref via process fail (or embedder defined cb) But anyway, Since C++ streams are outdated then I'm not going to support clones for them :) |
|
C++ streams won't disappear entirely before december. It will disappear soonish but not likely before December. |
just to confirm then, we don't need support them for the startup snapshot, right? |
|
I wouldn't think so. The plan is to remove the C++ impl of web streams entirely as soon as possible. We won't be able to start the switch until after the black friday limited deployment window so it definitely won't be before December. |
V8 serializes the backing store of every off-heap typed array that is not detached or out of bounds, including one whose ArrayBuffer has no bytes: unlike SerializeJSArrayBuffer(), SerializeJSTypedArray() does not check whether the buffer is empty. On load it allocates a zero-length backing store, whose start is null, and memcpy()s the zero bytes to it, which is undefined behavior that UBSan reports and aborts on. node:zlib keeps six such views at module scope (its flush buffers, each a Buffer over one shared new ArrayBuffer(0)), so every @all-autogates zlib test failed in the ASan build once C++-streams Workers became eligible for the snapshot. V8 runs the internal-fields serializer callback for each embedder field of every ArrayBuffer view the context reaches. serializeInternalFields() now counts such a typed array once, at its first field, in the counter it already keeps for fields the snapshot cannot carry, so the zygote fails and the Worker starts without a snapshot. A typed array that keeps its bytes on the V8 heap, a DataView, an empty ArrayBuffer and a view of a detached buffer are all serialized soundly and still transfer. snapshot-test gains a zygote that keeps such a view and one that keeps each of the cases that still transfer. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
kFlushBuffers held six Buffers over one shared new ArrayBuffer(0). Each is an off-heap typed array over a zero-length ArrayBuffer, which the zygote rejects, so every Worker importing node:zlib started without a startup snapshot. Buffer.alloc(0) gives each flush buffer its own zero-length typed array, which V8 keeps on its heap and serializes soundly. Each is still a distinct zero-length Buffer carrying its flush flag. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Under @all-autogates, the Worker of "structured logging with console methods" starts from a startup snapshot now that C++-streams Workers are eligible, and the module registry logs "module registry restored from startup snapshot" at INFO on restore. TestServer installs no JsonLogger, so KJ writes that line as plain text into the stream the test reads, and expectLogLine() handed it to the check expecting the Worker's first JSON console log. expectLogLine() now skips lines about the startup snapshot, as test_process_stdio.sh already does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…aration wrappable.h declares isolateRegisterExternalReference(), and every file that includes setup.h sees that declaration, so clang-tidy's readability-redundant-declaration check failed the lint build on the second one in setup.h. The definition in setup.c++ stays. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
clang-tidy's readability-container-size-empty check failed the lint build on `entries.size() != 0`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
9d5d14b to
8c923b5
Compare
A FileSystemFileHandle or FileSystemDirectoryHandle is nothing more than a locator and a name: the underlying file or directory is resolved on every operation. Both now transfer through the startup snapshot as exactly that, and a restored handle re-resolves against the VFS of the Worker it is restored into. The zygote's VFS is gone by the time a handle is restored, and the restore pass runs before the new Worker's context exists, so a clone is built without a VFS: the handle's `vfs` reference becomes a kj::Maybe that is none only for a clone. Wrappable gains a snapshotContextReady() hook for state that lives on the context. Worker::Script::installVirtualFileSystemOnContext() calls it on every object with a live wrapper, through IsolateBase::notifySnapshotContextReady(), once the VFS is in its context slot, and the handles bind to that VFS there. This happens before any JavaScript runs in the restored context, so getVfs() only asserts that the handle is bound.
An AsyncResource created at the top level, outside any AsyncContextFrame, captures neither a frame nor an IoContext, so a fresh instance stands in for it in a Worker started from the snapshot. One created inside a frame holds a jsg::Ref to that frame, which a clone cannot carry, and stays unclonable.
`#[jsg_resource(snapshot_stateless)]` declares that any fresh instance of a Rust resource type is interchangeable with any other, as C++ `jsgSnapshotStateless` does, and requires `Default`. Every Rust resource shares one CppHeapPointerTag, so such a type cannot be recorded by tag alone: the Rust-side C++ `Wrappable` now overrides `snapshotClone()` and asks the resource for a fresh instance through a new `GarbageCollected::snapshot_recreate` hook, which the macro generates for a stateless type. The instance is leaked as the trait object a `Wrappable` built without a strong reference takes over (`snapshot_recreate_leak`), as the restore path requires; a JavaScript caller that later unwraps it takes an `Rc` of its own. A live instance of any other Rust resource type still keeps the Worker out of the pipeline.
A span created outside an IoContext, at a Worker's top level for instance, records nothing: its state is a NoopSpanState the Span owns, so a fresh no-op state stands in for it in a Worker started from the snapshot. A span of a request holds its state through an IoOwn and stays unclonable.
A signal that has not aborted and that nothing is attached to (no listeners or event handler attributes, no abort algorithms, no native or RPC registrations, no AbortSignal.any() links) transfers as a fresh signal with the same flag.
Head branch was pushed to by a user without write access
|
Note also that all JS-visible APIs are moving to either TypeScript or Rust over the coming few months. |
Reverts "Fail the zygote on a typed array over a zero-length ArrayBuffer" (c04c729). V8 calls the internal-field serializer for an ArrayBuffer view only when it is built with embedder fields for views. The open-source Bazel build of V8 gives them two, but edgeworker builds V8 with GN's v8_array_buffer_view_internal_field_count = 0, so there serializeInternalFields() never sees the view and the check did nothing: snapshot-test's zygote with such a view did not throw, which failed the internal debug build. node:zlib keeps its flush buffers on the V8 heap, so Workers that import it are not affected. A Worker's own top level can still leave such a view reachable; docs/startup-snapshot.md now describes that case, and the zlib comment points there instead of to the removed check. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
clang-tidy's readability-container-size-empty check failed the lint build on the five `size() > 0` checks. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
clippy's use_self lint failed the lint build on the repeated type name. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The comment pointed to "docs/startup-snapshot.md §Failures". Shipped sources are compiled into the binary whole, comments included, and edgeworker's guarded-module-source-test requires them to be ASCII, so the section sign failed it. The comment now names the section in words. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Before any case runs, the test builds about 25 startup snapshots, one per zygote Worker. That takes 6-10 seconds in a debug build on x86 and just over 15 seconds on edgeworker's arm64 debug build. Edgeworker gives medium tests 15 seconds, so the test's @all-autogates variant times out there in most runs; workerd's internal builds for #8405 and other PRs since have needed retries to get past it. Its cases take about 200ms, so it is slow to start rather than stuck. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Before any case runs, the test builds about 25 startup snapshots, one per zygote Worker. That takes 6-10 seconds in a debug build on x86 and just over 15 seconds on edgeworker's arm64 debug build. Edgeworker gives medium tests 15 seconds, so the test's @all-autogates variant times out there in most runs; workerd's internal builds for #8405 and other PRs since have needed retries to get past it. Its cases take about 200ms, so it is slow to start rather than stuck. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Before any case runs, the test builds about 25 startup snapshots, one per zygote Worker. That takes 6-10 seconds in a debug build on x86 and just over 15 seconds on edgeworker's arm64 debug build. Edgeworker gives medium tests 15 seconds, so the test's @all-autogates variant times out there in most runs; workerd's internal builds for #8405 and other PRs since have needed retries to get past it. Its cases take about 200ms, so it is slow to start rather than stuck. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Support for the snapshot: