mirror of
https://github.com/coder/coder.git
synced 2026-06-02 20:48:20 +00:00
fix(agent/agentcontainers): prevent reassigning proc.agent until successful (#18609)
This commit is contained in:
committed by
GitHub
parent
09cc906981
commit
4f44dd08a9
@@ -188,7 +188,7 @@ func (a *subAgentAPIClient) List(ctx context.Context) ([]SubAgent, error) {
|
||||
return agents, nil
|
||||
}
|
||||
|
||||
func (a *subAgentAPIClient) Create(ctx context.Context, agent SubAgent) (SubAgent, error) {
|
||||
func (a *subAgentAPIClient) Create(ctx context.Context, agent SubAgent) (_ SubAgent, err error) {
|
||||
a.logger.Debug(ctx, "creating sub agent", slog.F("name", agent.Name), slog.F("directory", agent.Directory))
|
||||
|
||||
displayApps := make([]agentproto.CreateSubAgentRequest_DisplayApp, 0, len(agent.DisplayApps))
|
||||
@@ -233,19 +233,27 @@ func (a *subAgentAPIClient) Create(ctx context.Context, agent SubAgent) (SubAgen
|
||||
if err != nil {
|
||||
return SubAgent{}, err
|
||||
}
|
||||
defer func() {
|
||||
if err != nil {
|
||||
// Best effort.
|
||||
_, _ = a.api.DeleteSubAgent(ctx, &agentproto.DeleteSubAgentRequest{
|
||||
Id: resp.GetAgent().GetId(),
|
||||
})
|
||||
}
|
||||
}()
|
||||
|
||||
agent.Name = resp.Agent.Name
|
||||
agent.ID, err = uuid.FromBytes(resp.Agent.Id)
|
||||
agent.Name = resp.GetAgent().GetName()
|
||||
agent.ID, err = uuid.FromBytes(resp.GetAgent().GetId())
|
||||
if err != nil {
|
||||
return agent, err
|
||||
return SubAgent{}, err
|
||||
}
|
||||
agent.AuthToken, err = uuid.FromBytes(resp.Agent.AuthToken)
|
||||
agent.AuthToken, err = uuid.FromBytes(resp.GetAgent().GetAuthToken())
|
||||
if err != nil {
|
||||
return agent, err
|
||||
return SubAgent{}, err
|
||||
}
|
||||
|
||||
for _, appError := range resp.AppCreationErrors {
|
||||
app := apps[appError.Index]
|
||||
for _, appError := range resp.GetAppCreationErrors() {
|
||||
app := apps[appError.GetIndex()]
|
||||
|
||||
a.logger.Warn(ctx, "unable to create app",
|
||||
slog.F("agent_name", agent.Name),
|
||||
|
||||
Reference in New Issue
Block a user