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

testing/iotest: ErrTimeout fails os.IsTimeout #37263

Closed
dolmen opened this issue Feb 17, 2020 · 4 comments
Closed

testing/iotest: ErrTimeout fails os.IsTimeout #37263

dolmen opened this issue Feb 17, 2020 · 4 comments
Labels
Milestone

Comments

@dolmen
Copy link

@dolmen dolmen commented Feb 17, 2020

What version of Go are you using (go version)?

$ go version
1.13.7

Does this issue reproduce with the latest release?

Yes.

https://play.golang.org/p/T4bwPszSzM0

What did you do?

package main

import (
	"fmt"
	"os"
	"testing/iotest"
)

func main() {
	fmt.Println(os.IsTimeout(iotest.ErrTimeout))
}

What did you expect to see?

true

What did you see instead?

false

@changkun
Copy link
Contributor

@changkun changkun commented Feb 17, 2020

This result is consistent since the day that @ianlancetaylor introduces os.IsTimeout in Go 1.10.
However iotest.ErrTimeout lives way longer than io.IsTimeout.

The question is whether the Go team will recognize this as expected behavior with more documentation or a bug that should be fixed.

@dolmen
Copy link
Author

@dolmen dolmen commented Feb 17, 2020

I think that iotest.TimeoutReader is just useless for writing I/O tests if iotest.ErrTimeout isn't matched by os.IsTimeout.

Making it match is just switching ErrTimeout from being built from errors.New to using a specific type that has a Timeout method.

type errTimeout struct{}

func (errTimeout) Error() string {
    return "timeout"
}

func (errTimeout) Timeout() bool {
    return true
}

var ErrTimeout error = errTimeout{}

I can provide this as a PR (with added documentation).

@toothrot
Copy link
Contributor

@toothrot toothrot commented Feb 18, 2020

Also /cc-ing @mpvl @josharian as owners of testing

Just for some context, os.ErrTimeout was removed in #33411. There's also some discussion that seems related in #30322.

@toothrot toothrot added this to the Backlog milestone Feb 18, 2020
@rsc
Copy link
Contributor

@rsc rsc commented Oct 20, 2020

os.IsTimeout does what it does and won't be changing. The comments need to be updated to mark it as deprecated - use errors.Is instead. Fixing the doc comments is #41122 .

@rsc rsc closed this Oct 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.