]> Cypherpunks repositories - gostls13.git/commitdiff
Revert "net/http: wrap client errors"
authorCherry Mui <cherryyz@google.com>
Fri, 26 Jan 2024 17:28:45 +0000 (17:28 +0000)
committerGopher Robot <gobot@golang.org>
Fri, 26 Jan 2024 17:51:15 +0000 (17:51 +0000)
This reverts CL 533119.

Reason for revert: the test fails frequently, see #65287.

Fixes #65287.

Change-Id: I5bf2ee2b7ce435608ff76b892da261c0a4a189bf
Reviewed-on: https://go-review.googlesource.com/c/go/+/558916
Reviewed-by: Bryan Mills <bcmills@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Cherry Mui <cherryyz@google.com>

src/net/http/client.go
src/net/http/client_test.go
src/net/http/transport.go

index 45b9b915b4ae8c51464a6af191bcecfb4e1c5619..ee6de24fc19e4fbe8003a3def4fdcc426acd0ae4 100644 (file)
@@ -726,7 +726,7 @@ func (c *Client) do(req *Request) (retres *Response, reterr error) {
                        reqBodyClosed = true
                        if !deadline.IsZero() && didTimeout() {
                                err = &httpError{
-                                       err:     fmt.Errorf("%w (Client.Timeout exceeded while awaiting headers)", err),
+                                       err:     err.Error() + " (Client.Timeout exceeded while awaiting headers)",
                                        timeout: true,
                                }
                        }
@@ -969,7 +969,7 @@ func (b *cancelTimerBody) Read(p []byte) (n int, err error) {
        }
        if b.reqDidTimeout() {
                err = &httpError{
-                       err:     fmt.Errorf("%w (Client.Timeout exceeded or context cancellation while reading body)", err),
+                       err:     err.Error() + " (Client.Timeout or context cancellation while reading body)",
                        timeout: true,
                }
        }
index 7c71da139a1e0fd0f0f8784e2f1e3a92ae87b6d2..7459b9cb6ed1df3a42d4ed54a54abc8748b3dffd 100644 (file)
@@ -2127,22 +2127,3 @@ func testProbeZeroLengthBody(t *testing.T, mode testMode) {
                t.Fatalf("server got body %q, want %q", gotBody, content)
        }
 }
-
-func TestClientTimeoutReturnsContextDeadlineExceeded(t *testing.T) {
-       run(t, testClientTimeoutReturnsContextDeadlineExceeded)
-}
-func testClientTimeoutReturnsContextDeadlineExceeded(t *testing.T, mode testMode) {
-       doneCh := make(chan struct{})
-       defer close(doneCh)
-       cst := newClientServerTest(t, mode, HandlerFunc(func(w ResponseWriter, r *Request) {
-               <-doneCh
-               w.WriteHeader(200)
-       }))
-       // check that, upon exceeding Client.Timeout, the returned error is context.DeadlineExceeded.
-       cst.c.Timeout = 1 * time.Millisecond
-       req, _ := NewRequest("GET", cst.ts.URL, nil)
-       _, err := cst.c.Do(req)
-       if !errors.Is(err, context.DeadlineExceeded) {
-               t.Fatalf("expected context.DeadlineExceeded, got %v", err)
-       }
-}
index 6a1234e7f25525ec55609e2886851afc91303b56..57c70e72f9522c93a643f48c649d2288c7e62640 100644 (file)
@@ -2556,17 +2556,15 @@ type writeRequest struct {
 }
 
 type httpError struct {
-       err     error
+       err     string
        timeout bool
 }
 
-func (e *httpError) Error() string        { return e.err.Error() }
-func (e *httpError) Timeout() bool        { return e.timeout }
-func (e *httpError) Temporary() bool      { return true }
-func (e *httpError) Is(target error) bool { return errors.Is(e.err, target) }
-func (e *httpError) Unwrap() error        { return e.err }
+func (e *httpError) Error() string   { return e.err }
+func (e *httpError) Timeout() bool   { return e.timeout }
+func (e *httpError) Temporary() bool { return true }
 
-var errTimeout error = &httpError{err: errors.New("net/http: timeout awaiting response headers"), timeout: true}
+var errTimeout error = &httpError{err: "net/http: timeout awaiting response headers", timeout: true}
 
 // errRequestCanceled is set to be identical to the one from h2 to facilitate
 // testing.