Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Avoid assert when internal WritableStream aborted twice #715

Merged
merged 1 commit into from
May 30, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions src/workerd/api/streams/internal.c++
Original file line number Diff line number Diff line change
Expand Up @@ -896,26 +896,31 @@ jsg::Promise<void> WritableStreamInternalController::doAbort(
jsg::Lock& js,
v8::Local<v8::Value> reason,
AbortOptions options) {
// If maybePendingRejection is set, then the returned abort promise will be rejected
// If maybePendingAbort is set, then the returned abort promise will be rejected
// with the specified error once the abort is completed, otherwise the promise will
// be resolved with undefined.

// If there is already an abort pending, return that pending promise
// instead of trying to schedule another.
KJ_IF_MAYBE(pendingAbort, maybePendingAbort) {
pendingAbort->reject = options.reject;
auto promise = pendingAbort->whenResolved();
if (options.handled) {
promise.markAsHandled();
}
return kj::mv(promise);
}

KJ_IF_MAYBE(writable, state.tryGet<Writable>()) {
auto exception = js.exceptionToKj(js.v8Ref(reason));
if (queue.empty()) {
KJ_ASSERT(maybePendingAbort == nullptr);
(*writable)->abort(kj::cp(exception));
doError(js, reason);
return options.reject ?
rejectedMaybeHandledPromise<void>(js, reason, options.handled) :
js.resolvedPromise();
}

KJ_IF_MAYBE(pendingAbort, maybePendingAbort) {
pendingAbort->reject = options.reject;
return pendingAbort->whenResolved();
}

maybePendingAbort = PendingAbort(js, reason, options.reject);
auto promise = KJ_ASSERT_NONNULL(maybePendingAbort).whenResolved();
if (options.handled) {
Expand Down