Skip to content

fix(log): increase coder rpcConnectTimeout to 30s #313

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

Merged
merged 2 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion log/coder.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ import (
)

var (
rpcConnectTimeout = 10 * time.Second
// We set a relatively high connection timeout for the initial connection.
// There is an unfortunate race between the envbuilder container starting and the
// associated provisioner job completing.
rpcConnectTimeout = 30 * time.Second
logSendGracePeriod = 10 * time.Second
minAgentAPIV2 = "v2.9"
)
Expand Down
49 changes: 49 additions & 0 deletions log/coder_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,55 @@ func TestCoder(t *testing.T) {
require.ErrorIs(t, err, context.DeadlineExceeded)
<-handlerDone
})

// In this test, we validate that a 401 error on the initial connect
// results in a retry. When envbuilder initially attempts to connect
// using the Coder agent token, the workspace build may not yet have
// completed.
t.Run("V2Retry", func(t *testing.T) {
t.Parallel()
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()

token := uuid.NewString()
done := make(chan struct{})
handlerSend := make(chan int)
handler := func(w http.ResponseWriter, r *http.Request) {
t.Logf("test handler: %s", r.URL.Path)
if r.URL.Path == "/api/v2/buildinfo" {
w.Header().Set("Content-Type", "application/json")
_, _ = w.Write([]byte(`{"version": "v2.9.0"}`))
return
}
code := <-handlerSend
t.Logf("test handler response: %d", code)
w.WriteHeader(code)
}
srv := httptest.NewServer(http.HandlerFunc(handler))
defer srv.Close()

u, err := url.Parse(srv.URL)
require.NoError(t, err)
var connectError error
go func() {
defer close(handlerSend)
defer close(done)
_, _, connectError = Coder(ctx, u, token)
}()

// Initial: unauthorized
handlerSend <- http.StatusUnauthorized
// 2nd try: still unauthorized
handlerSend <- http.StatusUnauthorized
// 3rd try: authorized
handlerSend <- http.StatusOK

cancel()

<-done
require.ErrorContains(t, connectError, "failed to WebSocket dial")
require.ErrorIs(t, connectError, context.Canceled)
})
}

type fakeLogDest struct {
Expand Down