Skip to content

Commit 8f2b433

Browse files
Revert "fix(pro): wait for outer tunnels to exit and clean up properly"
This reverts commit 4856dbd.
1 parent 112e81a commit 8f2b433

File tree

6 files changed

+16
-41
lines changed

6 files changed

+16
-41
lines changed

cmd/ssh.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ type SSHCmd struct {
4444
SetEnvVars []string
4545

4646
Stdio bool
47+
JumpContainer bool
4748
AgentForwarding bool
4849
GPGAgentForwarding bool
4950
GitSSHSignatureForwarding bool
@@ -435,7 +436,7 @@ func (cmd *SSHCmd) startTunnel(ctx context.Context, devPodConfig *config.Config,
435436
if cmd.Proxy {
436437
go func() {
437438
if err := cmd.startRunnerServices(ctx, devPodConfig, containerClient, log); err != nil {
438-
log.Debug(err)
439+
log.Error(err)
439440
}
440441
}()
441442
}

pkg/inject/inject.go

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,9 @@ import (
99
"io"
1010
"os"
1111
"strings"
12-
"sync"
1312
"time"
1413

1514
"github.com/loft-sh/devpod/pkg/command"
16-
"github.com/loft-sh/devpod/pkg/util"
1715
"github.com/loft-sh/log"
1816
perrors "github.com/pkg/errors"
1917
)
@@ -116,8 +114,7 @@ func InjectAndExecute(
116114
case err = <-execErrChan:
117115
result = <-injectChan
118116
case result = <-injectChan:
119-
// give exec some time to properly terminate and clean up
120-
util.WaitForChan(execErrChan, 2*time.Second)
117+
// we don't wait for the command termination here and will just retry on error
121118
}
122119

123120
// prefer result error
@@ -129,7 +126,7 @@ func InjectAndExecute(
129126
return result.wasExecuted, nil
130127
}
131128

132-
log.Debug("Rerun command as binary was injected")
129+
log.Debugf("Rerun command as binary was injected")
133130
delayedStderr.Start()
134131
return true, exec(ctx, scriptParams.Command, stdin, stdout, delayedStderr)
135132
}
@@ -284,19 +281,14 @@ func readLine(reader io.Reader) (string, error) {
284281
}
285282

286283
func pipe(toStdin io.Writer, fromStdin io.Reader, toStdout io.Writer, fromStdout io.Reader) error {
287-
var err error
288-
wg := sync.WaitGroup{}
289-
wg.Add(1)
284+
errChan := make(chan error, 2)
290285
go func() {
291-
defer wg.Done()
292-
_, err = io.Copy(toStdout, fromStdout)
286+
_, err := io.Copy(toStdout, fromStdout)
287+
errChan <- err
293288
}()
294-
wg.Add(1)
295289
go func() {
296-
defer wg.Done()
297-
_, err = io.Copy(toStdin, fromStdin)
290+
_, err := io.Copy(toStdin, fromStdin)
291+
errChan <- err
298292
}()
299-
300-
wg.Wait()
301-
return err
293+
return <-errChan
302294
}

pkg/ssh/server/ssh.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ func (s *Server) handler(sess ssh.Session) {
140140
var err error
141141
if isPty {
142142
s.log.Debugf("Execute SSH server PTY command: %s", strings.Join(cmd.Args, " "))
143-
err = s.HandlePTY(sess, ptyReq, winCh, cmd, nil)
143+
err = HandlePTY(sess, ptyReq, winCh, cmd, nil)
144144
} else {
145145
s.log.Debugf("Execute SSH server command: %s", strings.Join(cmd.Args, " "))
146146
err = s.HandleNonPTY(sess, cmd)
@@ -201,17 +201,16 @@ func (s *Server) HandleNonPTY(sess ssh.Session, cmd *exec.Cmd) (err error) {
201201
}
202202
}()
203203

204-
// order is important here!
205-
err = cmd.Wait()
206204
waitGroup.Wait()
205+
err = cmd.Wait()
207206
if err != nil {
208207
return err
209208
}
210209

211210
return nil
212211
}
213212

214-
func (s *Server) HandlePTY(
213+
func HandlePTY(
215214
sess ssh.Session,
216215
ptyReq ssh.Pty,
217216
winCh <-chan ssh.Window,

pkg/tunnel/container.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313
"github.com/loft-sh/devpod/pkg/config"
1414
"github.com/loft-sh/devpod/pkg/provider"
1515
devssh "github.com/loft-sh/devpod/pkg/ssh"
16-
"github.com/loft-sh/devpod/pkg/util"
1716
"github.com/loft-sh/log"
1817
"github.com/pkg/errors"
1918
"github.com/sirupsen/logrus"
@@ -129,10 +128,8 @@ func (c *ContainerHandler) Run(ctx context.Context, handler Handler, cfg *config
129128
// wait for result
130129
select {
131130
case err := <-containerChan:
132-
util.WaitForChan(tunnelChan, 2*time.Second)
133131
return errors.Wrap(err, "tunnel to container")
134132
case err := <-tunnelChan:
135-
util.WaitForChan(containerChan, 2*time.Second)
136133
return errors.Wrap(err, "connect to server")
137134
}
138135
}
@@ -207,6 +204,9 @@ func (c *ContainerHandler) runRunInContainer(ctx context.Context, sshClient *ssh
207204
defer stdoutWriter.Close()
208205
defer cancel()
209206

207+
c.log.Debugf("Run container tunnel")
208+
defer c.log.Debugf("Container tunnel exited")
209+
210210
command := fmt.Sprintf("'%s' agent container-tunnel --workspace-info '%s'", c.client.AgentPath(), workspaceInfo)
211211
if c.log.GetLevel() == logrus.DebugLevel {
212212
command += " --debug"

pkg/tunnel/direct.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@ import (
44
"context"
55
"io"
66
"os"
7-
"time"
87

98
devssh "github.com/loft-sh/devpod/pkg/ssh"
10-
"github.com/loft-sh/devpod/pkg/util"
119
"github.com/pkg/errors"
1210
)
1311

@@ -54,10 +52,8 @@ func NewTunnel(ctx context.Context, tunnel Tunnel, handler Handler) error {
5452
// wait for result
5553
select {
5654
case err := <-innerTunnelChan:
57-
util.WaitForChan(outerTunnelChan, 2*time.Second)
5855
return errors.Wrap(err, "inner tunnel")
5956
case err := <-outerTunnelChan:
60-
util.WaitForChan(innerTunnelChan, 2*time.Second)
6157
return errors.Wrap(err, "outer tunnel")
6258
}
6359
}

pkg/util/channel.go

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)