diff --git a/core/local/local_test.go b/core/local/local_test.go index 23eb2a7fed3..76eb0fe59eb 100644 --- a/core/local/local_test.go +++ b/core/local/local_test.go @@ -1026,7 +1026,7 @@ func TestDNSResolver(t *testing.T) { expErr := sr(`dial tcp 127.0.0.254:HTTPBIN_PORT: connect: connection refused`) if runtime.GOOS == "windows" { - expErr = "context deadline exceeded" + expErr = "Request timeout" } for name, tc := range testCases { tc := tc diff --git a/js/modules/k6/http/request_test.go b/js/modules/k6/http/request_test.go index 954cc162a37..f09c3b14218 100644 --- a/js/modules/k6/http/request_test.go +++ b/js/modules/k6/http/request_test.go @@ -326,7 +326,7 @@ func TestRequestAndBatch(t *testing.T) { `)) endTime := time.Now() require.Error(t, err) - assert.Contains(t, err.Error(), "context deadline exceeded") + assert.Contains(t, err.Error(), "Request timeout") assert.WithinDuration(t, startTime.Add(1*time.Second), endTime, 2*time.Second) logEntry := hook.LastEntry() @@ -344,7 +344,7 @@ func TestRequestAndBatch(t *testing.T) { `)) endTime := time.Now() require.Error(t, err) - assert.Contains(t, err.Error(), "context deadline exceeded") + assert.Contains(t, err.Error(), "Request timeout") assert.WithinDuration(t, startTime.Add(1*time.Second), endTime, 2*time.Second) logEntry := hook.LastEntry() diff --git a/lib/netext/httpext/error_codes.go b/lib/netext/httpext/error_codes.go index 7c9f2fd90bf..28915829be5 100644 --- a/lib/netext/httpext/error_codes.go +++ b/lib/netext/httpext/error_codes.go @@ -46,6 +46,7 @@ const ( // non specific defaultErrorCode errCode = 1000 defaultNetNonTCPErrorCode errCode = 1010 + requestTimeoutErrorCode errCode = 1050 // DNS errors defaultDNSErrorCode errCode = 1100 dnsNoSuchHostErrorCode errCode = 1101 @@ -56,7 +57,6 @@ const ( tcpBrokenPipeErrorCode errCode = 1201 netUnknownErrnoErrorCode errCode = 1202 tcpDialErrorCode errCode = 1210 - tcpDialTimeoutErrorCode errCode = 1211 tcpDialRefusedErrorCode errCode = 1212 tcpDialUnknownErrnoCode errCode = 1213 tcpResetByPeerErrorCode errCode = 1220 @@ -86,7 +86,6 @@ const ( const ( tcpResetByPeerErrorCodeMsg = "%s: connection reset by peer" - tcpDialTimeoutErrorCodeMsg = "dial: i/o timeout" tcpDialRefusedErrorCodeMsg = "dial: connection refused" tcpBrokenPipeErrorCodeMsg = "%s: broken pipe" netUnknownErrnoErrorCodeMsg = "%s: unknown errno `%d` on %s with message `%s`" @@ -98,6 +97,7 @@ const ( http2ConnectionErrorCodeMsg = "http2: connection error with http2 ErrCode %s" x509HostnameErrorCodeMsg = "x509: certificate doesn't match hostname" x509UnknownAuthority = "x509: unknown authority" + requestTimeoutErrorCodeMsg = "Request timeout" ) func http2ErrCodeOffset(code http2.ErrCode) errCode { @@ -140,10 +140,6 @@ func errorCodeForNetOpError(err *net.OpError) (errCode, string) { } } - // err.Op is "dial" - if err.Timeout() { - return tcpDialTimeoutErrorCode, tcpDialTimeoutErrorCodeMsg - } if iErr, ok := err.Err.(*os.SyscallError); ok { if errno, ok := iErr.Err.(syscall.Errno); ok { if errno == syscall.ECONNREFUSED || diff --git a/lib/netext/httpext/error_codes_test.go b/lib/netext/httpext/error_codes_test.go index c1dd5e42c90..26ee2574a5d 100644 --- a/lib/netext/httpext/error_codes_test.go +++ b/lib/netext/httpext/error_codes_test.go @@ -129,7 +129,6 @@ func TestTCPErrors(t *testing.T) { econnrefused = &net.OpError{Net: "tcp", Op: "dial", Err: &os.SyscallError{Err: syscall.ECONNREFUSED}} errnounknown = &net.OpError{Net: "tcp", Op: "dial", Err: &os.SyscallError{Err: syscall.E2BIG}} tcperror = &net.OpError{Net: "tcp", Err: errors.New("tcp error")} - timeoutedError = &net.OpError{Net: "tcp", Op: "dial", Err: timeoutError(true)} notTimeoutedError = &net.OpError{Net: "tcp", Op: "dial", Err: timeoutError(false)} ) @@ -141,7 +140,6 @@ func TestTCPErrors(t *testing.T) { tcpDialUnknownErrnoCode: errnounknown, defaultTCPErrorCode: tcperror, tcpDialErrorCode: notTimeoutedError, - tcpDialTimeoutErrorCode: timeoutedError, } testMapOfErrorCodes(t, testTable) diff --git a/lib/netext/httpext/transport.go b/lib/netext/httpext/transport.go index c812bf35a8a..add7b538c6f 100644 --- a/lib/netext/httpext/transport.go +++ b/lib/netext/httpext/transport.go @@ -22,6 +22,7 @@ package httpext import ( "context" + "errors" "net" "net/http" "net/http/httptrace" @@ -243,6 +244,10 @@ func (t *transport) RoundTrip(req *http.Request) (*http.Response, error) { reqWithTracer := req.WithContext(httptrace.WithClientTrace(ctx, tracer.Trace())) resp, err := t.state.Transport.RoundTrip(reqWithTracer) + var netError net.Error + if errors.As(err, &netError) && netError.Timeout() { + err = NewK6Error(requestTimeoutErrorCode, requestTimeoutErrorCodeMsg, netError) + } t.saveCurrentRequest(&unfinishedRequest{ ctx: ctx, tracer: tracer,