Files
teleport/lib/utils/errors_test.go
T
Julia Ogris 38bb2a94d9 app: Raise upstream response-header cap to 1h (#66647)
The app service caps how long it waits for an upstream HTTP response
to start arriving via http.Transport.ResponseHeaderTimeout. The cap
was set to 5 minutes, which kills legitimate long-running requests
(slow POSTs, long-poll handshakes, delayed first bytes) even though
the upstream is healthy and actively processing. Relax the cap to 1
hour rather than removing it: the app service deliberately leaves
ReadTimeout and WriteTimeout unset on its inbound http.Server, has
no MaxConnsPerHost on outbound, and no listener-side limiter, so
this transport-level cap is the only Teleport-side bound on
per-request lifetime. Raising it to 1 hour gives long-running
workloads room to finish while still reaping wedged upstreams.

Pick up a separate latent fix while in the area: extend
utils.CanExplainNetworkError so HTTP/2 response-header timeouts also
surface the friendly diagnostic page. HTTP/1 timeouts already match
the context.DeadlineExceeded case via timeoutError.Is. HTTP/2's
http2httpError does not wrap context.DeadlineExceeded; it implements
net.Error with Timeout() returning true. Combine both shapes into one
case, also catching syscall.ETIMEDOUT and other net.Error timeouts.

Use testing/synctest for the transport-level regression tests so the
multi-minute simulated waits are instant in wall-clock terms. Inject
a net.Pipe via tr.DialContext to keep real socket I/O out of the
synctest bubble.
2026-05-12 23:22:29 +00:00

83 lines
2.4 KiB
Go

/*
* Teleport
* Copyright (C) 2026 Gravitational, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package utils
import (
"errors"
"testing"
"github.com/stretchr/testify/require"
)
// fakeTimeoutError mirrors http2httpError: net.Error with Timeout() ==
// true and no Is method. Temporary() is required by the net.Error
// interface (deprecated but not removed as of Go 1.25).
type fakeTimeoutError struct{ msg string }
func (e *fakeTimeoutError) Error() string { return e.msg }
func (e *fakeTimeoutError) Timeout() bool { return true }
func (e *fakeTimeoutError) Temporary() bool { return true }
// fakeNonTimeoutError is a net.Error with Timeout() == false.
type fakeNonTimeoutError struct{ msg string }
func (e *fakeNonTimeoutError) Error() string { return e.msg }
func (e *fakeNonTimeoutError) Timeout() bool { return false }
func (e *fakeNonTimeoutError) Temporary() bool { return true }
func TestCanExplainNetworkError_TimeoutFallthrough(t *testing.T) {
t.Parallel()
tests := []struct {
name string
err error
wantOK bool
wantSub string
}{
{
name: "http2 response header timeout shape",
err: &fakeTimeoutError{msg: "http2: timeout awaiting response headers"},
wantOK: true,
wantSub: "Context Deadline Exceeded",
},
{
name: "net error without Timeout returns no explanation",
err: &fakeNonTimeoutError{msg: "some non-timeout net error"},
wantOK: false,
},
{
name: "plain error returns no explanation",
err: errors.New("not a net.Error"),
wantOK: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
msg, ok := CanExplainNetworkError(tt.err)
require.Equal(t, tt.wantOK, ok)
if tt.wantSub != "" {
require.Contains(t, msg, tt.wantSub)
}
})
}
}