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

Make shutdown close the input/output-streams. #7749

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

badeend
Copy link
Contributor

@badeend badeend commented Jan 4, 2024

Make tcp-socket::shutdown close the input/output-streams.
This was already specified in the WITs, but not implemented nor enforced by any tests.

This was already specified in the WITs, but not enforced by any tests.
@badeend badeend requested a review from a team as a code owner January 4, 2024 18:21
@badeend badeend requested review from fitzgen and removed request for a team January 4, 2024 18:21
Copy link
Member

@alexcrichton alexcrichton left a comment

Choose a reason for hiding this comment

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

Thanks! One question but otherwise looks good 👍

Comment on lines +295 to +298
if self.inner.is_shut_down_for_sending() {
self.last_write = LastWrite::Done;
return Err(StreamError::Closed);
}
Copy link
Member

Choose a reason for hiding this comment

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

Should this be checked after checking for Waiting below? It's a bit weird to have a pending write and then call shutdown, but I think the shutdown syscall will cause the background write to wake up and report its failure?

Copy link
Contributor Author

@badeend badeend Jan 6, 2024

Choose a reason for hiding this comment

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

The user-facing behavior implemented in this PR seems correct to me. I.e. to return StreamError::Closed even if an background write was still in progress.

With the current solution it's the responsibility of the caller to properly wait for all data to be fully acknowledged/flushed before calling shutdown.

I think the true question is: whether or not to abandon the background write (as currently current implemented) or detach the running background tasks and let the background write finish up even after the WASI output stream has been closed. Because this issue is not limited to just shutdown, but also drop.

Copy link
Member

Choose a reason for hiding this comment

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

Oh I'm not advocating for letting this proceed in the background, I'm more thinking that it might be best to shuffle this to get the response from the background task before checking the shutdown status. I'm under the impression that a shutdown will cancel pending writes by marking the socket as writable and returning Ok(0) or EPIPE or something like that. That would mean that after the shutdown it's not an indefinite block for the background task to finish up and for us to get the result.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it might be best to shuffle this to get the response from the background task before checking the shutdown status.

What would be the benefit? On line 296 I reset the last_write status which drops the AbortOnDropJoinHandle. So the background task will always be aborted, right?

Copy link
Member

Choose a reason for hiding this comment

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

It's true yeah that largely the same thing will happen, but I'd at least personally prefer to explicitly clean up the task rather than let it get cleaned up in the background if possible. It's sort of six-to-one-half-dozen-or-the-other though.

I'm not certain of the portability of the behavior of marking the socket as writable and cancelling all writes once shutdown is issued though. If that's not the actual OS behavior then switching the order here wouldn't work.

Given the discussion here though I'm also a bit wary of cancelling active writes since that could show up as surprising for users, so maybe I should be advocating for letting this proceed in the background...

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

Successfully merging this pull request may close these issues.

None yet

2 participants