|
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 | funcrunCmd(ctx context.Context,client*codersdk.Client,agentID uuid.UUID,cmdstring) ([]byte,error) {
|
479 |
| -varerrerror |
480 |
| -varclosers []func()error |
481 |
| -deferfunc() { |
482 |
| -iferr!=nil { |
483 |
| -for_,c:=rangeclosers { |
484 |
| -iferr2:=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 | iferr!=nil {
|
492 | 480 | returnnil,xerrors.Errorf("dial workspace agent: %w",err)
|
493 | 481 | }
|
494 |
| -closers=append(closers,agentConn.Close) |
| 482 | +deferagentConn.Close() |
495 | 483 |
|
496 | 484 | sshClient,err:=agentConn.SSHClient(ctx)
|
497 | 485 | iferr!=nil {
|
498 | 486 | returnnil,xerrors.Errorf("get ssh client: %w",err)
|
499 | 487 | }
|
500 |
| -closers=append(closers,sshClient.Close) |
| 488 | +defersshClient.Close() |
501 | 489 |
|
502 | 490 | sshSession,err:=sshClient.NewSession()
|
503 | 491 | iferr!=nil {
|
504 | 492 | returnnil,xerrors.Errorf("new ssh session: %w",err)
|
505 | 493 | }
|
506 |
| -closers=append(closers,sshSession.Close) |
| 494 | +defersshSession.Close() |
507 | 495 |
|
508 | 496 | cmdBytes,err:=sshSession.CombinedOutput(cmd)
|
509 | 497 | iferr!=nil {
|
|