Skip to content

Commit ff9b347

Browse files
committed
make sure the close algorithm always run async
1 parent e43a3f5 commit ff9b347

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1210,7 +1210,19 @@ void WritableImpl<Self>::advanceQueueIfNeeded(jsg::Lock& js, jsg::Ref<Self> self
12101210
finishInFlightClose(js, kj::mv(self), reason.getHandle(js));
12111211
});
12121212

1213-
maybeRunAlgorithm(js, algorithms.close, kj::mv(onSuccess), kj::mv(onFailure));
1213+
// Per the spec, the close algorithm should always run asynchronously, even if
1214+
// there's no user-provided close handler. This ensures that releaseLock() can
1215+
// reject the closed promise before the close completes.
1216+
if (FeatureFlags::get(js).getPedanticWpt() && algorithms.close == kj::none) {
1217+
KJ_IF_SOME(ioContext, IoContext::tryCurrent()) {
1218+
js.resolvedPromise().then(
1219+
js, ioContext.addFunctor(kj::mv(onSuccess)), ioContext.addFunctor(kj::mv(onFailure)));
1220+
} else {
1221+
js.resolvedPromise().then(js, kj::mv(onSuccess), kj::mv(onFailure));
1222+
}
1223+
} else {
1224+
maybeRunAlgorithm(js, algorithms.close, kj::mv(onSuccess), kj::mv(onFailure));
1225+
}
12141226
}
12151227
return;
12161228
}

src/wpt/streams-test.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -734,12 +734,7 @@ export default {
734734
'Closing a writable stream with in-flight writes below the high water mark delays the close call properly',
735735
],
736736
},
737-
'writable-streams/close.any.js': {
738-
comment: 'To be investigated',
739-
expectedFailures: [
740-
'releaseLock() should not change the result of sync close()',
741-
],
742-
},
737+
'writable-streams/close.any.js': {},
743738
'writable-streams/constructor.any.js': {
744739
comment: 'These are mostly about validation of params',
745740
expectedFailures:

0 commit comments

Comments
 (0)