mirror of
https://github.com/coder/coder.git
synced 2025-07-15 22:20:27 +00:00
fix(cli/ssh): retry on autostart conflict (#16058)
This commit is contained in:
committed by
GitHub
parent
53d9c7ebe4
commit
ba6e84dec3
@ -33,6 +33,7 @@ import (
|
||||
|
||||
"cloud.google.com/go/compute/metadata"
|
||||
"github.com/fullsailor/pkcs7"
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/golang-jwt/jwt/v4"
|
||||
"github.com/google/uuid"
|
||||
"github.com/moby/moby/pkg/namesgenerator"
|
||||
@ -146,6 +147,11 @@ type Options struct {
|
||||
Database database.Store
|
||||
Pubsub pubsub.Pubsub
|
||||
|
||||
// APIMiddleware inserts middleware before api.RootHandler, this can be
|
||||
// useful in certain tests where you want to intercept requests before
|
||||
// passing them on to the API, e.g. for synchronization of execution.
|
||||
APIMiddleware func(http.Handler) http.Handler
|
||||
|
||||
ConfigSSH codersdk.SSHConfigResponse
|
||||
|
||||
SwaggerEndpoint bool
|
||||
@ -555,7 +561,14 @@ func NewWithAPI(t testing.TB, options *Options) (*codersdk.Client, io.Closer, *c
|
||||
setHandler, cancelFunc, serverURL, newOptions := NewOptions(t, options)
|
||||
// We set the handler after server creation for the access URL.
|
||||
coderAPI := coderd.New(newOptions)
|
||||
setHandler(coderAPI.RootHandler)
|
||||
rootHandler := coderAPI.RootHandler
|
||||
if options.APIMiddleware != nil {
|
||||
r := chi.NewRouter()
|
||||
r.Use(options.APIMiddleware)
|
||||
r.Mount("/", rootHandler)
|
||||
rootHandler = r
|
||||
}
|
||||
setHandler(rootHandler)
|
||||
var provisionerCloser io.Closer = nopcloser{}
|
||||
if options.IncludeProvisionerDaemon {
|
||||
provisionerCloser = NewTaggedProvisionerDaemon(t, coderAPI, "test", options.ProvisionerDaemonTags)
|
||||
|
@ -381,6 +381,10 @@ func (b *Builder) buildTx(authFunc func(action policy.Action, object rbac.Object
|
||||
code := http.StatusInternalServerError
|
||||
if rbac.IsUnauthorizedError(err) {
|
||||
code = http.StatusForbidden
|
||||
} else if database.IsUniqueViolation(err) {
|
||||
// Concurrent builds may result in duplicate
|
||||
// workspace_builds_workspace_id_build_number_key.
|
||||
code = http.StatusConflict
|
||||
}
|
||||
return BuildError{code, "insert workspace build", err}
|
||||
}
|
||||
|
Reference in New Issue
Block a user