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
FrozenDueToAge NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made.
Milestone

Comments

@dolmen
Copy link
Contributor

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
Member

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
Contributor Author

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

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 the NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. label Feb 18, 2020
@toothrot toothrot added this to the Backlog milestone Feb 18, 2020
@rsc
Copy link
Contributor

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 as completed Oct 20, 2020
@golang golang locked and limited conversation to collaborators Oct 20, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made.
Projects
None yet
Development

No branches or pull requests

5 participants