# Policy for \`io::ErrorKind::Interrupted\`

**URL:** <https://internals.rust-lang.org/t/policy-for-io-errorkind-interrupted/3315>\
**Category:** libs\
**Created:** [March 28, 2016, 8:18pm UTC](https://internals.rust-lang.org/t/policy-for-io-errorkind-interrupted/3315 "2016-03-28T20:18:02Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![troplin](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/troplin/32/1182_2.png) [@troplin](https://internals.rust-lang.org/u/troplin)\
**Post date:** [March 28, 2016, 8:18pm UTC](https://internals.rust-lang.org/t/policy-for-io-errorkind-interrupted/3315/1 "2016-03-28T20:18:02Z")

</div>

Is there a policy for handling `io::ErrorKind::Interrupted` in libstd? From what I can see, most (all?) nontrivial functions just ignore it and retry.

That’s a bit unfortunate. I find myself reimplementing half of `std::io` just to be able to interrupt those calls.

IMO the policy should be one of the following:

1. Remove io::ErrorKind::Interrupted alltogether. (Even for `read` and `write`)
2. (Preferred) Break on io::ErrorKind::Interrupted if possible. (Meaning if the function can be retried safely)

The current state is a bit pointless. The error is there and has to be considered, but it’s still not really usable for those who need it.

EDIT: An example of a function that could be retried safely is `io::Read::read_to_end(...)`

---

<div class="post-metadata">

**Author:** ![sfackler](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/sfackler/32/9_2.png) [@sfackler](https://internals.rust-lang.org/u/sfackler)\
**Post date:** [March 28, 2016, 9:07pm UTC](https://internals.rust-lang.org/t/policy-for-io-errorkind-interrupted/3315/2 "2016-03-28T21:07:54Z")

</div>

The [IO reform RFC](https://github.com/rust-lang/rfcs/blob/master/text/0517-io-os-reform.md#read) covers the policy around read interruption.

---

<div class="post-metadata">

**Author:** ![troplin](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/troplin/32/1182_2.png) [@troplin](https://internals.rust-lang.org/u/troplin)\
**Post date:** [March 28, 2016, 10:01pm UTC](https://internals.rust-lang.org/t/policy-for-io-errorkind-interrupted/3315/3 "2016-03-28T22:01:52Z")

</div>

Thanks for the pointer.

I don’t really agree with the reasoning… signals are not the only use case for interruption. There’s also explicit interruption e.g. with an adapter on top of existing `Read` implementations.

I agree that EINTR is a a nuisance if you don’t explicitly want to deal with it. But if you have to, you suddenly also have to deal with lots of code that doesn’t handle it “correctly”.

But it’s too late now for changes anyway. I guess I have to bite the bullet and write everything myself instead of using `std`. 😞

---

<div class="post-metadata">

**Author:** ![withoutboats](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/withoutboats/32/4560_2.png) [@withoutboats](https://internals.rust-lang.org/u/withoutboats)\
**Post date:** [March 29, 2016, 1:36am UTC](https://internals.rust-lang.org/t/policy-for-io-errorkind-interrupted/3315/4 "2016-03-29T01:36:25Z")

</div>

I hope you can write it as a library for other people who need this functionality as well. 🙂

---

<div class="post-metadata">

**Author:** ![troplin](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/troplin/32/1182_2.png) [@troplin](https://internals.rust-lang.org/u/troplin)\
**Post date:** [March 29, 2016, 5:10pm UTC](https://internals.rust-lang.org/t/policy-for-io-errorkind-interrupted/3315/5 "2016-03-29T17:10:21Z")

</div>

If it turns out to be worth publishing I’ll certainly do so.

---

<div class="post-metadata">

**Author:** ![troplin](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/troplin/32/1182_2.png) [@troplin](https://internals.rust-lang.org/u/troplin)\
**Post date:** [March 30, 2016, 9:53pm UTC](https://internals.rust-lang.org/t/policy-for-io-errorkind-interrupted/3315/6 "2016-03-30T21:53:44Z")

</div>

There you go: [https://crates.io/crates/netio/](https://crates.io/crates/netio/)

Comments and feedback welcome!

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/system/32/14092_2.png) [@system](https://internals.rust-lang.org/u/system)\
**Post date:** [March 25, 2019, 8:25am UTC](https://internals.rust-lang.org/t/policy-for-io-errorkind-interrupted/3315/7 "2019-03-25T08:25:59Z")

</div>

Closed on March 25, 2019, 8:25am UTC

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
