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

Add InProgress variant to io::ErrorKind #92

Closed
aviramha opened this issue Aug 29, 2022 · 14 comments
Closed

Add InProgress variant to io::ErrorKind #92

aviramha opened this issue Aug 29, 2022 · 14 comments
Labels
ACP-accepted API Change Proposal is accepted (seconded with no objections) api-change-proposal A proposal to add or alter unstable APIs in the standard libraries T-libs-api

Comments

@aviramha
Copy link

Proposal

Add InProgress variant to io::ErrorKind to support cases where OS error is libc::EINPROGRESS

Problem statement

While working on API that relies on io::last_os_error I found out that kind field of io::Error is set to Uncategorized which means I can't "safely" use .kind() to check if it's a specific error, in our case libc::EINPROGRESS

Motivation, use-cases

Our code example that can be simplified given the addition.

Solution sketches

Links and related work

Sent a PR of the proposed change
rust-lang/rust#101155 (review)

@aviramha aviramha added api-change-proposal A proposal to add or alter unstable APIs in the standard libraries T-libs-api labels Aug 29, 2022
@aviramha
Copy link
Author

@thomcc brought up in the PR that it's similar to WouldBlock. I do agree but my objective is to be aware when EINPROGRESS happened and that's Linux error codes quirks. To be honest I'm okay with matching EINPROGRESS to WouldBlock but it might be weird and intuitive for most people.

@thomcc
Copy link
Member

thomcc commented Aug 29, 2022

I don't think it makes sense for us to reflect all errno values in ErrorKind -- this is what raw_os_error is for, after all.

But, on the one hand, WouldBlock is quite specific -- it definitely implies that it maps to EWOULDBLOCK.

@aviramha
Copy link
Author

I don't think it makes sense for us to reflect all errno values in ErrorKind -- this is what raw_os_error is for, after all.

But, on the one hand, WouldBlock is quite specific -- it definitely implies that it maps to EWOULDBLOCK.

I'm fine with that. I am not really synced with the general thought of best practice in this so really up to the maintainers 😊

@aviramha
Copy link
Author

aviramha commented Sep 17, 2022

Took @thomcc and changed the PR to use WouldBlock error instead of introducing new variant, InProgress

@m-ou-se m-ou-se closed this as completed May 17, 2023
@joshtriplett
Copy link
Member

Sounds like this got resolved without adding this variant.

We may, in the future, want to add such a variant for other purposes, but it sounds like we can close this ACP for now.

@joshtriplett
Copy link
Member

This seems to have gotten closed on the theory that EINPROGRESS could get mapped to WouldBlock, but as discussed on the PR and in today's libs-api meeting, that's not the right mapping. If we do provide a mapping for this, it should be to a separate ErrorKind variant.

@joshtriplett joshtriplett reopened this Aug 1, 2023
@joshtriplett
Copy link
Member

We don't have a consensus in @rust-lang/libs-api to create an ErrorKind variant for this.

Leaving this open in the hopes that we reach a consensus to do so.

@aviramha
Copy link
Author

aviramha commented Aug 1, 2023

Thanks for discussing this.
I believe that EINPROGRESS is quite commonly used - it isn't a seldom error so if there's anything I can do to convince adding it - I'd love to push for it :)

@m-ou-se
Copy link
Member

m-ou-se commented Aug 15, 2023

Originally we thought it'd make sense to merge this with ErrorKind::WouldBlock, but then later it seemed clear that EAGAIN and EINPROGRESS should not be treated the same in most cases.

However, when we try to discuss this in the team meeting, we get stuck on not having a complete overview of how these errors occur and are handled in practice, especially on different platforms.

So, to move this forward, we'll need a bit more context to answer questions like: When does this error occur? How does one usually handle this error? Does it exist on non-unix platforms? If so, does it represent the exact same thing? Would adding this ErrorKind result in more or less platform-specific code in practice?

@aviramha
Copy link
Author

aviramha commented Aug 15, 2023

Thanks @m-ou-se - I will try to provide my findings.
Personally, I don't think that mapping EINPROGRESS to WouldBlock would make sense tbh (and that was my opinion since I created thie issue)

When does it occur?

It occurs when you call a procedure which can take time to complete, and isn't blocking to completion - in sockets for example when the socket is set to not block, and you call connect it'd return immediately with the EINPRGORESS.

Example from stdlib:
https://github.com/rust-lang/rust/blob/c1699a79a603faa8b522a4b51553b6781913a50e/library/std/src/sys/solid/net.rs#L242

How does one usually handle this error?

It's considered a non-error, it's a way of letting the caller know that the operation didn't fail but also didn't complete yet. We originally faced it because our code "errored" while getting this while it's not a "true" error. The handling is success - continue.

Does it exist on non-unix platforms?

It exists on Windows and other POSIX-compliant systems, not sure about other?
The representation of EINPRGORESS across platforms is same, and in all isn't same as EWOULDBLOCK or EAGAIN.
Also seems all (?) platforms on rust's libc implement it.

Would adding this ErrorKind result in more or less platform-specific code in practice?

Hard to say, but right now we're just accessing the raw os instead of using the variant, which what annoyed me to create this issue.

@Amanieu Amanieu added the I-libs-api-nominated Indicates that an issue has been nominated for discussion during a team meeting. label Sep 17, 2024
@joshtriplett
Copy link
Member

We discussed this once more in today's libs-api meeting, and confirmed that we want this to be a separate ErrorKind variant, InProgress.

The primary intended distinction here (various platform portability issues aside) is that WouldBlock means you should retry the operation when ready, and InProgress means you shouldn't retry the operation.

@dtolnay dtolnay closed this as completed Sep 24, 2024
@dtolnay dtolnay added ACP-accepted API Change Proposal is accepted (seconded with no objections) and removed I-libs-api-nominated Indicates that an issue has been nominated for discussion during a team meeting. labels Sep 24, 2024
@aviramha
Copy link
Author

aviramha commented Sep 24, 2024

Woohoo! Great news. Is it okay if I reopen my PR?

@joshtriplett
Copy link
Member

@aviramha Please do reopen, or make a new one, whichever is simpler for providing a PR that applies.

@aviramha
Copy link
Author

Done rust-lang/rust#130789

tgross35 added a commit to tgross35/rust that referenced this issue Sep 24, 2024
add InProgress ErrorKind gated behind io_error_inprogress feature

Follow up on rust-lang/libs-team#92 (comment)
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Sep 25, 2024
Rollup merge of rust-lang#130789 - aviramha:add_inprogress, r=Noratrieb

add InProgress ErrorKind gated behind io_error_inprogress feature

Follow up on rust-lang/libs-team#92 (comment)
github-actions bot pushed a commit to rust-lang/miri that referenced this issue Sep 25, 2024
add InProgress ErrorKind gated behind io_error_inprogress feature

Follow up on rust-lang/libs-team#92 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ACP-accepted API Change Proposal is accepted (seconded with no objections) api-change-proposal A proposal to add or alter unstable APIs in the standard libraries T-libs-api
Projects
None yet
Development

No branches or pull requests

6 participants