Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Neuter the EncodedAsyncOutputStream on end/abort #308

Merged
merged 1 commit into from
Jan 23, 2023

Conversation

harrishancock
Copy link
Collaborator

@harrishancock harrishancock commented Jan 23, 2023

Original commit description by @jasnell:

Because kj::AsyncOutputStream does not have an explicit end, some impls use their destructor to perform final writes, some of those using held bare refs to other objects. If the EncodedAsyncOutputStream happens to be held by an IoOwn (or some other mechanism that extends its lifetime past that of those deeply nested bare refs) then we can have a problem.

Here, we modify EncodedAsyncOutputStream to free inner when either end or abort are called, effectively neutering it and allowing the inner to perform any additional cleanup it needs on end.

Because kj::AsyncOutputStream does not have an explicit end, some impls
use their destructor to perform final writes, some of those using held
bare refs to other objects. If the EncodedAsyncOutputStream happens to
be held by an IoOwn (or some other mechanism that extends its lifetime
past that of those deeply nested bare refs) then we can have a problem.

Here, we modify EncodedAsyncOutputStream to free inner when either end
or abort are called, effectively neutering it and allowing the inner to
perform any additional cleanup it needs on end.
@harrishancock harrishancock requested a review from jasnell January 23, 2023 19:19
@harrishancock harrishancock merged commit f6ea662 into main Jan 23, 2023
@harrishancock harrishancock deleted the harris/add-james-patch branch January 23, 2023 20:56
}

KJ_IF_MAYBE(stream, inner.tryGet<kj::Own<kj::AsyncOutputStream>>()) {
if (auto casted = dynamic_cast<kj::AsyncIoStream*>(stream->get())) {
casted->shutdownWrite();
}
promise = promise.attach(kj::mv(*stream));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is redundant FWIW -- promise is always READY_NOW here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants