Skip to content

Commit 3a909a4

Browse files
committed
Fixup gc visitation in streams readers and writers
1 parent 4226541 commit 3a909a4

File tree

4 files changed

+17
-4
lines changed

4 files changed

+17
-4
lines changed

src/workerd/api/streams/internal.c++

+1-1
Original file line numberDiff line numberDiff line change
@@ -1838,7 +1838,7 @@ void WritableStreamInternalController::visitForGc(jsg::GcVisitor& visitor) {
18381838
for (auto& event : queue) {
18391839
KJ_SWITCH_ONEOF(event.event) {
18401840
KJ_CASE_ONEOF(write, Write) {
1841-
visitor.visit(write.promise, write.ref);
1841+
visitor.visit(write.promise);
18421842
}
18431843
KJ_CASE_ONEOF(close, Close) {
18441844
visitor.visit(close.promise);

src/workerd/api/streams/internal.h

-1
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,6 @@ class WritableStreamInternalController: public WritableStreamController {
283283
kj::Maybe<jsg::Promise<void>::Resolver> promise;
284284
std::shared_ptr<v8::BackingStore> ownBytes;
285285
kj::ArrayPtr<const kj::byte> bytes;
286-
kj::Maybe<jsg::Ref<WritableStream>> ref;
287286
};
288287
struct Close {
289288
kj::Maybe<jsg::Promise<void>::Resolver> promise;

src/workerd/api/streams/readable.c++

+8-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,14 @@ void ReaderImpl::releaseLock(jsg::Lock& js) {
155155
}
156156

157157
void ReaderImpl::visitForGc(jsg::GcVisitor& visitor) {
158-
visitor.visit(closedPromise);
158+
KJ_IF_SOME(readable, state.tryGet<Attached>()) {
159+
visitor.visit(readable);
160+
} else {
161+
// If the reader is attached, then visiting the readable should visit the
162+
// closedPromise via visiting the associated resolver.
163+
// Otherwise, we need to visit it directly if they are set.
164+
visitor.visit(closedPromise);
165+
}
159166
}
160167

161168
// ======================================================================================

src/workerd/api/streams/writable.c++

+8-1
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,14 @@ bool WritableStream::inspectExpectsBytes() {
197197
}
198198

199199
void WritableStreamDefaultWriter::visitForGc(jsg::GcVisitor& visitor) {
200-
visitor.visit(closedPromise, readyPromise);
200+
KJ_IF_SOME(writable, state.tryGet<Attached>()) {
201+
visitor.visit(writable);
202+
} else {
203+
// If the writer is attached, then visiting the writable should visit the
204+
// closedPromise and readyPromise via visiting their associated resolvers.
205+
// Otherwise, we need to visit those directly if they are set.
206+
visitor.visit(closedPromise, readyPromise);
207+
}
201208
}
202209

203210
// ======================================================================================

0 commit comments

Comments
 (0)