|
5 | 5 | "context"
|
6 | 6 | "encoding/base64"
|
7 | 7 | "encoding/json"
|
8 |
| - "errors" |
9 | 8 | "io"
|
10 | 9 | "net/http"
|
11 | 10 | "strings"
|
@@ -476,34 +475,23 @@ func sanitizeEnv(kvs map[string]string) {
|
476 | 475 |
|
477 | 476 | // TODO: use rpty instead? which is less liable to fail?
|
478 | 477 | func runCmd(ctx context.Context, client *codersdk.Client, agentID uuid.UUID, cmd string) ([]byte, error) {
|
479 |
| - var err error |
480 |
| - var closers []func() error |
481 |
| - defer func() { |
482 |
| - if err != nil { |
483 |
| - for _, c := range closers { |
484 |
| - if err2 := c(); err2 != nil { |
485 |
| - err = errors.Join(err, err2) |
486 |
| - } |
487 |
| - } |
488 |
| - } |
489 |
| - }() |
490 | 478 | agentConn, err := client.DialWorkspaceAgent(ctx, agentID, &codersdk.DialWorkspaceAgentOptions{})
|
491 | 479 | if err != nil {
|
492 | 480 | return nil, xerrors.Errorf("dial workspace agent: %w", err)
|
493 | 481 | }
|
494 |
| - closers = append(closers, agentConn.Close) |
| 482 | + defer agentConn.Close() |
495 | 483 |
|
496 | 484 | sshClient, err := agentConn.SSHClient(ctx)
|
497 | 485 | if err != nil {
|
498 | 486 | return nil, xerrors.Errorf("get ssh client: %w", err)
|
499 | 487 | }
|
500 |
| - closers = append(closers, sshClient.Close) |
| 488 | + defer sshClient.Close() |
501 | 489 |
|
502 | 490 | sshSession, err := sshClient.NewSession()
|
503 | 491 | if err != nil {
|
504 | 492 | return nil, xerrors.Errorf("new ssh session: %w", err)
|
505 | 493 | }
|
506 |
| - closers = append(closers, sshSession.Close) |
| 494 | + defer sshSession.Close() |
507 | 495 |
|
508 | 496 | cmdBytes, err := sshSession.CombinedOutput(cmd)
|
509 | 497 | if err != nil {
|
|
0 commit comments