Skip to content

Commit 2e2833a

Browse files
authored
[ssh-gateway] fix missing output when running simple command (#18366)
* [ssh-gateway] fix missing output when running simple command * upgrade golang-crypto library * only close when all of stdout stderr request stream finish * upgrade golang-crypto
1 parent fb7784f commit 2e2833a

File tree

5 files changed

+53
-38
lines changed

5 files changed

+53
-38
lines changed

components/ws-proxy/go.mod

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ require (
77
github.com/gitpod-io/gitpod/common-go v0.0.0-00010101000000-000000000000
88
github.com/gitpod-io/gitpod/supervisor/api v0.0.0-00010101000000-000000000000
99
github.com/gitpod-io/gitpod/ws-manager/api v0.0.0-00010101000000-000000000000
10-
github.com/gitpod-io/golang-crypto v0.0.0-20220823040820-b59f56dfbab3
10+
github.com/gitpod-io/golang-crypto v0.0.0-20230731181530-3ce7221eee49
1111
github.com/go-ozzo/ozzo-validation v3.6.0+incompatible
1212
github.com/google/go-cmp v0.5.9
1313
github.com/gorilla/handlers v1.5.1
@@ -73,9 +73,9 @@ require (
7373
github.com/xtgo/uuid v0.0.0-20140804021211-a0b114877d4c // indirect
7474
go.uber.org/atomic v1.7.0 // indirect
7575
golang.org/x/oauth2 v0.5.0 // indirect
76-
golang.org/x/sys v0.8.0 // indirect
77-
golang.org/x/term v0.8.0 // indirect
78-
golang.org/x/text v0.9.0 // indirect
76+
golang.org/x/sys v0.10.0 // indirect
77+
golang.org/x/term v0.10.0 // indirect
78+
golang.org/x/text v0.11.0 // indirect
7979
golang.org/x/time v0.3.0 // indirect
8080
gomodules.xyz/jsonpatch/v2 v2.3.0 // indirect
8181
google.golang.org/appengine v1.6.7 // indirect

components/ws-proxy/go.sum

Lines changed: 10 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components/ws-proxy/pkg/sshproxy/forward.go

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ func (s *Server) ChannelForward(ctx context.Context, session *Session, targetCon
2020
targetChan, targetReqs, err := targetConn.OpenChannel(originChannel.ChannelType(), originChannel.ExtraData())
2121
if err != nil {
2222
log.WithFields(log.OWI("", session.WorkspaceID, session.InstanceID)).Error("open target channel error")
23-
originChannel.Reject(ssh.ConnectionFailed, "open target channel error")
23+
_ = originChannel.Reject(ssh.ConnectionFailed, "open target channel error")
2424
return
2525
}
2626
defer targetChan.Close()
@@ -53,32 +53,46 @@ func (s *Server) ChannelForward(ctx context.Context, session *Session, targetCon
5353
close(maskedReqs)
5454
}()
5555

56+
originChannelWg := sync.WaitGroup{}
57+
originChannelWg.Add(3)
58+
targetChannelWg := sync.WaitGroup{}
59+
targetChannelWg.Add(3)
60+
61+
wg := sync.WaitGroup{}
62+
wg.Add(2)
63+
5664
go func() {
57-
io.Copy(targetChan, originChan)
58-
targetChan.CloseWrite()
65+
defer wg.Done()
66+
_, _ = io.Copy(targetChan, originChan)
67+
targetChannelWg.Done()
68+
targetChannelWg.Wait()
69+
_ = targetChan.Close()
5970
}()
6071

6172
go func() {
62-
io.Copy(originChan, targetChan)
63-
originChan.CloseWrite()
73+
defer wg.Done()
74+
_, _ = io.Copy(originChan, targetChan)
75+
originChannelWg.Done()
76+
originChannelWg.Wait()
77+
_ = originChan.Close()
6478
}()
6579

6680
go func() {
67-
io.Copy(targetChan.Stderr(), originChan.Stderr())
81+
_, _ = io.Copy(targetChan.Stderr(), originChan.Stderr())
82+
targetChannelWg.Done()
6883
}()
6984

7085
go func() {
71-
io.Copy(originChan.Stderr(), targetChan.Stderr())
86+
_, _ = io.Copy(originChan.Stderr(), targetChan.Stderr())
87+
originChannelWg.Done()
7288
}()
7389

74-
wg := sync.WaitGroup{}
75-
forward := func(sourceReqs <-chan *ssh.Request, targetChan ssh.Channel) {
76-
defer wg.Done()
90+
forward := func(sourceReqs <-chan *ssh.Request, targetChan ssh.Channel, channelWg *sync.WaitGroup) {
91+
defer channelWg.Done()
7792
for ctx.Err() == nil {
7893
select {
7994
case req, ok := <-sourceReqs:
8095
if !ok {
81-
targetChan.Close()
8296
return
8397
}
8498
b, err := targetChan.SendRequest(req.Type, req.WantReply, req.Payload)
@@ -92,9 +106,8 @@ func (s *Server) ChannelForward(ctx context.Context, session *Session, targetCon
92106
}
93107
}
94108

95-
wg.Add(2)
96-
go forward(maskedReqs, targetChan)
97-
go forward(targetReqs, originChan)
109+
go forward(maskedReqs, targetChan, &targetChannelWg)
110+
go forward(targetReqs, originChan, &originChannelWg)
98111

99112
wg.Wait()
100113
log.WithFields(log.OWI("", session.WorkspaceID, session.InstanceID)).Debug("session forward stop")

install/installer/go.mod

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ require (
126126
github.com/gitpod-io/gitpod/components/scrubber v0.0.0-00010101000000-000000000000 // indirect
127127
github.com/gitpod-io/gitpod/content-service v0.0.0-00010101000000-000000000000 // indirect
128128
github.com/gitpod-io/gitpod/usage-api v0.0.0-00010101000000-000000000000 // indirect
129-
github.com/gitpod-io/golang-crypto v0.0.0-20220823040820-b59f56dfbab3 // indirect
129+
github.com/gitpod-io/golang-crypto v0.0.0-20230731181530-3ce7221eee49 // indirect
130130
github.com/go-errors/errors v1.4.2 // indirect
131131
github.com/go-gorp/gorp/v3 v3.0.5 // indirect
132132
github.com/go-logr/logr v1.2.4 // indirect
@@ -261,9 +261,9 @@ require (
261261
golang.org/x/net v0.10.0 // indirect
262262
golang.org/x/oauth2 v0.6.0 // indirect
263263
golang.org/x/sync v0.2.0 // indirect
264-
golang.org/x/sys v0.9.0 // indirect
265-
golang.org/x/term v0.9.0 // indirect
266-
golang.org/x/text v0.10.0 // indirect
264+
golang.org/x/sys v0.10.0 // indirect
265+
golang.org/x/term v0.10.0 // indirect
266+
golang.org/x/text v0.11.0 // indirect
267267
golang.org/x/time v0.3.0 // indirect
268268
golang.org/x/tools v0.9.1 // indirect
269269
gomodules.xyz/jsonpatch/v2 v2.3.0 // indirect

install/installer/go.sum

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)