Skip to content

Commit

Permalink
Merge pull request #2609 from cloudflare/jsnell/account-for-already-e…
Browse files Browse the repository at this point in the history
…mpty-queue
  • Loading branch information
jasnell authored Aug 27, 2024
2 parents 450b591 + 8850e4b commit 58c83c1
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/workerd/api/streams/internal.c++
Original file line number Diff line number Diff line change
Expand Up @@ -1590,6 +1590,8 @@ jsg::Promise<void> WritableStreamInternalController::writeLoopAfterFrontOutputLo
.then(js,
ioContext.addFunctor(
[this, check, maybeAbort, amountToWrite](jsg::Lock& js) -> jsg::Promise<void> {
// Under some conditions, the clean up has already happened.
if (queue.empty()) return js.resolvedPromise();
auto& request = check();
maybeResolvePromise(js, request.promise);
decreaseCurrentWriteBufferSize(js, amountToWrite);
Expand All @@ -1599,6 +1601,8 @@ jsg::Promise<void> WritableStreamInternalController::writeLoopAfterFrontOutputLo
}),
ioContext.addFunctor([this, check, maybeAbort, amountToWrite](
jsg::Lock& js, jsg::Value reason) -> jsg::Promise<void> {
// Under some conditions, the clean up has already happened.
if (queue.empty()) return js.resolvedPromise();
auto handle = reason.getHandle(js);
auto& request = check();
auto& writable = state.get<IoOwn<Writable>>();
Expand Down Expand Up @@ -1742,12 +1746,16 @@ jsg::Promise<void> WritableStreamInternalController::writeLoopAfterFrontOutputLo

return ioContext.awaitIo(js, writable->canceler.wrap(writable->sink->end()))
.then(js, ioContext.addFunctor([this, check](jsg::Lock& js) {
// Under some conditions, the clean up has already happened.
if (queue.empty()) return;
auto& request = check();
maybeResolvePromise(js, request.promise);
queue.pop_front();
finishClose(js);
}),
ioContext.addFunctor([this, check](jsg::Lock& js, jsg::Value reason) {
// Under some conditions, the clean up has already happened.
if (queue.empty()) return;
auto handle = reason.getHandle(js);
auto& request = check();
maybeRejectPromise<void>(js, request.promise, handle);
Expand Down

0 comments on commit 58c83c1

Please sign in to comment.