Skip to content

Commit 0e54d28

Browse files
committed
all: remove os.ErrTimeout
It is unclear whether the current definition of os.IsTimeout is desirable or not. Drop ErrTimeout for now so we can consider adding it (or some other error) in a future release with a corrected definition. Fixes #33411 Change-Id: I8b880da7d22afc343a08339eb5f0efd1075ecafe Reviewed-on: https://go-review.googlesource.com/c/go/+/188758 Reviewed-by: Russ Cox <[email protected]> Run-TryBot: Damien Neil <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent 2d1a1e0 commit 0e54d28

19 files changed

+8
-150
lines changed

api/go1.13.txt

-3
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,6 @@ pkg net/http, type Transport struct, ForceAttemptHTTP2 bool
209209
pkg net/http, type Transport struct, ReadBufferSize int
210210
pkg net/http, type Transport struct, WriteBufferSize int
211211
pkg net, method (*DNSConfigError) Unwrap() error
212-
pkg net, method (*DNSError) Is(error) bool
213-
pkg net, method (*OpError) Is(error) bool
214212
pkg net, method (*OpError) Unwrap() error
215213
pkg net, type DNSError struct, IsNotFound bool
216214
pkg net, type ListenConfig struct, KeepAlive time.Duration
@@ -237,7 +235,6 @@ pkg os (netbsd-arm64), const O_SYNC = 128
237235
pkg os (netbsd-arm64), const O_TRUNC = 1024
238236
pkg os (netbsd-arm64), const PathListSeparator = 58
239237
pkg os (netbsd-arm64), const PathSeparator = 47
240-
pkg os, var ErrTimeout error
241238
pkg path/filepath (netbsd-arm64-cgo), const ListSeparator = 58
242239
pkg path/filepath (netbsd-arm64-cgo), const Separator = 47
243240
pkg path/filepath (netbsd-arm64), const ListSeparator = 58

src/context/context.go

-4
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ package context
4949

5050
import (
5151
"errors"
52-
"internal/oserror"
5352
"internal/reflectlite"
5453
"sync"
5554
"time"
@@ -163,9 +162,6 @@ type deadlineExceededError struct{}
163162
func (deadlineExceededError) Error() string { return "context deadline exceeded" }
164163
func (deadlineExceededError) Timeout() bool { return true }
165164
func (deadlineExceededError) Temporary() bool { return true }
166-
func (deadlineExceededError) Is(target error) bool {
167-
return target == oserror.ErrTimeout
168-
}
169165

170166
// An emptyCtx is never canceled, has no values, and has no deadline. It is not
171167
// struct{}, since vars of this type must have distinct addresses.

src/context/context_test.go

-5
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@
55
package context
66

77
import (
8-
"errors"
98
"fmt"
109
"math/rand"
11-
"os"
1210
"runtime"
1311
"strings"
1412
"sync"
@@ -649,7 +647,4 @@ func XTestDeadlineExceededSupportsTimeout(t testingT) {
649647
if !i.Timeout() {
650648
t.Fatal("wrong value for timeout")
651649
}
652-
if !errors.Is(DeadlineExceeded, os.ErrTimeout) {
653-
t.Fatal("errors.Is(DeadlineExceeded, os.ErrTimeout) = false, want true")
654-
}
655650
}

src/go/build/deps_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ var pkgDeps = map[string][]string{
250250
"compress/gzip": {"L4", "compress/flate"},
251251
"compress/lzw": {"L4"},
252252
"compress/zlib": {"L4", "compress/flate"},
253-
"context": {"errors", "internal/oserror", "internal/reflectlite", "sync", "time"},
253+
"context": {"errors", "internal/reflectlite", "sync", "time"},
254254
"database/sql": {"L4", "container/list", "context", "database/sql/driver", "database/sql/internal"},
255255
"database/sql/driver": {"L4", "context", "time", "database/sql/internal"},
256256
"debug/dwarf": {"L4"},

src/internal/oserror/errors.go

-28
Original file line numberDiff line numberDiff line change
@@ -15,32 +15,4 @@ var (
1515
ErrExist = errors.New("file already exists")
1616
ErrNotExist = errors.New("file does not exist")
1717
ErrClosed = errors.New("file already closed")
18-
ErrTimeout = timeoutError{}
1918
)
20-
21-
type timeoutError struct{}
22-
23-
func (timeoutError) Error() string { return "deadline exceeded" }
24-
func (timeoutError) Timeout() bool { return true }
25-
26-
type temporaryError struct{}
27-
28-
func (temporaryError) Error() string { return "temporary error" }
29-
func (temporaryError) Temporary() bool { return true }
30-
31-
// IsTimeout reports whether err indicates a timeout.
32-
func IsTimeout(err error) bool {
33-
for err != nil {
34-
if err == ErrTimeout {
35-
return true
36-
}
37-
if x, ok := err.(interface{ Timeout() bool }); ok {
38-
return x.Timeout()
39-
}
40-
if x, ok := err.(interface{ Is(error) bool }); ok && x.Is(ErrTimeout) {
41-
return true
42-
}
43-
err = errors.Unwrap(err)
44-
}
45-
return false
46-
}

src/internal/oserror/errors_test.go

-43
This file was deleted.

src/internal/poll/fd.go

-5
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ package poll
1111

1212
import (
1313
"errors"
14-
"internal/oserror"
1514
)
1615

1716
// ErrNetClosing is returned when a network descriptor is used after
@@ -47,10 +46,6 @@ func (e *TimeoutError) Error() string { return "i/o timeout" }
4746
func (e *TimeoutError) Timeout() bool { return true }
4847
func (e *TimeoutError) Temporary() bool { return true }
4948

50-
func (e *TimeoutError) Is(target error) bool {
51-
return target == oserror.ErrTimeout
52-
}
53-
5449
// ErrNotPollable is returned when the file or socket is not suitable
5550
// for event notification.
5651
var ErrNotPollable = errors.New("not pollable")

src/net/cgo_unix.go

-9
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import "C"
2424

2525
import (
2626
"context"
27-
"os"
2827
"syscall"
2928
"unsafe"
3029
)
@@ -38,14 +37,6 @@ func (eai addrinfoErrno) Error() string { return C.GoString(C.gai_strerror(C.i
3837
func (eai addrinfoErrno) Temporary() bool { return eai == C.EAI_AGAIN }
3938
func (eai addrinfoErrno) Timeout() bool { return false }
4039

41-
func (eai addrinfoErrno) Is(target error) bool {
42-
switch target {
43-
case os.ErrTimeout:
44-
return eai.Timeout()
45-
}
46-
return false
47-
}
48-
4940
type portLookupResult struct {
5041
port int
5142
err error

src/net/http/transport.go

-12
Original file line numberDiff line numberDiff line change
@@ -2284,14 +2284,6 @@ func (e *httpError) Error() string { return e.err }
22842284
func (e *httpError) Timeout() bool { return e.timeout }
22852285
func (e *httpError) Temporary() bool { return true }
22862286

2287-
func (e *httpError) Is(target error) bool {
2288-
switch target {
2289-
case os.ErrTimeout:
2290-
return e.timeout
2291-
}
2292-
return false
2293-
}
2294-
22952287
var errTimeout error = &httpError{err: "net/http: timeout awaiting response headers", timeout: true}
22962288

22972289
// errRequestCanceled is set to be identical to the one from h2 to facilitate
@@ -2626,10 +2618,6 @@ func (tlsHandshakeTimeoutError) Timeout() bool { return true }
26262618
func (tlsHandshakeTimeoutError) Temporary() bool { return true }
26272619
func (tlsHandshakeTimeoutError) Error() string { return "net/http: TLS handshake timeout" }
26282620

2629-
func (tlsHandshakeTimeoutError) Is(target error) bool {
2630-
return target == os.ErrTimeout
2631-
}
2632-
26332621
// fakeLocker is a sync.Locker which does nothing. It's used to guard
26342622
// test-only fields when not under test, to avoid runtime atomic
26352623
// overhead.

src/net/net.go

-16
Original file line numberDiff line numberDiff line change
@@ -516,14 +516,6 @@ func (e *OpError) Temporary() bool {
516516
return ok && t.Temporary()
517517
}
518518

519-
func (e *OpError) Is(target error) bool {
520-
switch target {
521-
case os.ErrTimeout:
522-
return e.Timeout()
523-
}
524-
return false
525-
}
526-
527519
// A ParseError is the error type of literal network address parsers.
528520
type ParseError struct {
529521
// Type is the type of string that was expected, such as
@@ -615,14 +607,6 @@ func (e *DNSError) Timeout() bool { return e.IsTimeout }
615607
// error and return a DNSError for which Temporary returns false.
616608
func (e *DNSError) Temporary() bool { return e.IsTimeout || e.IsTemporary }
617609

618-
func (e *DNSError) Is(target error) bool {
619-
switch target {
620-
case os.ErrTimeout:
621-
return e.Timeout()
622-
}
623-
return false
624-
}
625-
626610
type writerOnly struct {
627611
io.Writer
628612
}

src/net/pipe.go

-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ package net
66

77
import (
88
"io"
9-
"os"
109
"sync"
1110
"time"
1211
)
@@ -85,10 +84,6 @@ func (timeoutError) Error() string { return "deadline exceeded" }
8584
func (timeoutError) Timeout() bool { return true }
8685
func (timeoutError) Temporary() bool { return true }
8786

88-
func (timeoutError) Is(target error) bool {
89-
return target == os.ErrTimeout
90-
}
91-
9287
type pipeAddr struct{}
9388

9489
func (pipeAddr) Network() string { return "pipe" }

src/net/timeout_test.go

-5
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77
package net
88

99
import (
10-
"errors"
1110
"fmt"
12-
"internal/oserror"
1311
"internal/poll"
1412
"internal/testenv"
1513
"io"
@@ -90,9 +88,6 @@ func TestDialTimeout(t *testing.T) {
9088
if nerr, ok := err.(Error); !ok || !nerr.Timeout() {
9189
t.Fatalf("#%d: %v", i, err)
9290
}
93-
if !errors.Is(err, oserror.ErrTimeout) {
94-
t.Fatalf("#%d: Dial error is not os.ErrTimeout: %v", i, err)
95-
}
9691
}
9792
}
9893
}

src/net/url/url.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ package url
1313
import (
1414
"errors"
1515
"fmt"
16-
"internal/oserror"
1716
"sort"
1817
"strconv"
1918
"strings"
@@ -28,7 +27,13 @@ type Error struct {
2827

2928
func (e *Error) Unwrap() error { return e.Err }
3029
func (e *Error) Error() string { return e.Op + " " + e.URL + ": " + e.Err.Error() }
31-
func (e *Error) Timeout() bool { return oserror.IsTimeout(e.Err) }
30+
31+
func (e *Error) Timeout() bool {
32+
t, ok := e.Err.(interface {
33+
Timeout() bool
34+
})
35+
return ok && t.Timeout()
36+
}
3237

3338
func (e *Error) Temporary() bool {
3439
t, ok := e.Err.(interface {

src/os/error.go

-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ var (
2222
ErrExist = errExist() // "file already exists"
2323
ErrNotExist = errNotExist() // "file does not exist"
2424
ErrClosed = errClosed() // "file already closed"
25-
ErrTimeout = errTimeout() // "deadline exceeded"
2625
ErrNoDeadline = errNoDeadline() // "file type does not support deadline"
2726
)
2827

@@ -31,7 +30,6 @@ func errPermission() error { return oserror.ErrPermission }
3130
func errExist() error { return oserror.ErrExist }
3231
func errNotExist() error { return oserror.ErrNotExist }
3332
func errClosed() error { return oserror.ErrClosed }
34-
func errTimeout() error { return oserror.ErrTimeout }
3533
func errNoDeadline() error { return poll.ErrNoDeadline }
3634

3735
type timeout interface {

src/syscall/syscall_js.go

-2
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,6 @@ func (e Errno) Error() string {
5858

5959
func (e Errno) Is(target error) bool {
6060
switch target {
61-
case oserror.ErrTimeout:
62-
return e.Timeout()
6361
case oserror.ErrPermission:
6462
return e == EACCES || e == EPERM
6563
case oserror.ErrExist:

src/syscall/syscall_nacl.go

-2
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,6 @@ func (e Errno) Error() string {
6565

6666
func (e Errno) Is(target error) bool {
6767
switch target {
68-
case oserror.ErrTimeout:
69-
return e.Timeout()
7068
case oserror.ErrPermission:
7169
return e == EACCES || e == EPERM
7270
case oserror.ErrExist:

src/syscall/syscall_plan9.go

-2
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ func NewError(s string) error { return ErrorString(s) }
2929

3030
func (e ErrorString) Is(target error) bool {
3131
switch target {
32-
case oserror.ErrTimeout:
33-
return e.Timeout()
3432
case oserror.ErrPermission:
3533
return checkErrMessageContent(e, "permission denied")
3634
case oserror.ErrExist:

src/syscall/syscall_unix.go

-2
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,6 @@ func (e Errno) Error() string {
121121

122122
func (e Errno) Is(target error) bool {
123123
switch target {
124-
case oserror.ErrTimeout:
125-
return e.Timeout()
126124
case oserror.ErrPermission:
127125
return e == EACCES || e == EPERM
128126
case oserror.ErrExist:

src/syscall/syscall_windows.go

-2
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,6 @@ const _ERROR_BAD_NETPATH = Errno(53)
115115

116116
func (e Errno) Is(target error) bool {
117117
switch target {
118-
case oserror.ErrTimeout:
119-
return e.Timeout()
120118
case oserror.ErrPermission:
121119
return e == ERROR_ACCESS_DENIED
122120
case oserror.ErrExist:

0 commit comments

Comments
 (0)