-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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
proposal: io: new Timeout interface implemented by errors #39798
Comments
ErrTimeout is a tricky one: see #33411 and the things it links to for reference. As for a Timeout interface in package io, I'm not sure. It seems to me like timeouts are not strictly related to I/O. |
Since almost every usage I could find related to error handling, |
As you say, we generally encourage Something like package os
var ErrTimeout timeoutError
type timeoutError struct{}
func (timeoutError) Error() string { return "timeout" }
func (timeoutError) Timeout() bool { return true }
func (e *PathError) Is(err error) bool {
if err == ErrTimeout {
return e.Timeout()
}
return false
} |
To be clear That being said, the proliferation of Since there seems to be consensus on |
That can be done for errors in the standard library, but we cannot easily update user-defined timeout errors to do the same. (See #33411 (comment).) |
We'd obviously never have used the #33411 argues against having a common classification for timeouts.
So I think the real question is: Should we be providing a way of identifying timeouts in general, or not? Obviously, we are providing that way right now in the form of On the other hand, if a common classification for timeouts is something we want, then adding |
I am relatively agnostic on the issue, so will let the more passionate among us decide.
Where would you want to update documentation? Even catching all standard library implementations will miss third party libraries. Do you think it is worth adding an immediately deprecated symbol to serve this purpose? |
If we decide that grouping together timeouts from different sources was a bad idea (which I don't have a strong opinion on at the moment), then we should probably remove documentation that mentions the |
Now that @neild mentions it, I agree: we shouldn't be pushing the I sent the documentation-only https://golang.org/cl/239705 to help with that process. |
I missed this before, but there is an extant If this is the direction we are pushing in, it strikes me that three classes of usage should be amended: methodsPublic symbols should be deprecated to clarify usage to consumers:
Probably good to deprecate internal symbols too:
godocAs already started by @ianlancetaylor, we should purge all mention from documentation, leaving the behaviour as vestigial. His CL 239705 covers:
But not:
callsiteWhile potentially overkill, it may be good to add a clarifying warning comment around current usage. It would serve to freeze the current implementation, while dissuading readers from copying the pattern.
|
The discussion above has died out, but it sounds like the general consensus was that while there may be some cleanup to do, we should probably not bother trying to define a "generic timeout", nor a predicate for checking for one. That said, it seems a bit too aggressive to deprecate the Timeout method on existing errors, but that's not what this proposal was suggesting. Based on the discussion, the proposal as currently titled - "io: new Timeout interface implemented by errors" - seems like a likely decline. |
No change in consensus, so declined. We still need to figure out timeouts, but a new Timeout interface isn't the way. |
So, to confirm you are declining both the new |
@rsc: I am going to close this out, since it is declined, and I think you forgot to do that? However, I would like clarification about what exactly was declined, see my previous comment. |
background
Currently there is a private interface in
net
,errors
, andos
that is used to check for if an error is a timeout:While these interfaces can only used inside the packages they are defined in, the specification leaks into many public apis for other packages:
net/http
,syscall
,context
, etc.implementation
We should expose one common interface:
alternatives
It would likely be better to expose
io.ErrTimeout
and ensure everybody implementserrors.Is(err, io.ErrTimeout)
, but that would be a breaking change, so it is not advocated for here. That being said, I am in favour of that too, but for compatibility, it would need to be both. I also recall their being a larger discussion, that I cannot find, about the topic ofErrTemporary
,ErrTimeout
, and the like.If we wanted to reserve
io.Timeout
for something better, we could call thisio.Timeouter
, but it sounds strange.io
may not be the right package either, butos
woudl make for a circular dependency anderrors
did did not seem, strictly speaking, better.drawbacks
This interface is not strictly speaking required, but it is a compile time contract between library and consumer, and does make the following code read better:
The text was updated successfully, but these errors were encountered: