Skip to content

Commit

Permalink
[ssh-gateway] only send heartbeat when it explicitly request pty
Browse files Browse the repository at this point in the history
  • Loading branch information
iQQBot committed Jun 28, 2022
1 parent e68d866 commit 420c212
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions components/ws-proxy/pkg/sshproxy/forward.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@ func (s *Server) ChannelForward(ctx context.Context, session *Session, targetCon
switch req.Type {
case "pty-req", "shell":
log.WithFields(log.OWI("", session.WorkspaceID, session.InstanceID)).Debugf("forwarding %s request", req.Type)
if req.WantReply {
req.Reply(true, []byte{})
req.WantReply = false
if channel, ok := originChan.(*heartbeatingChannel); ok && req.Type == "pty-req" {
channel.mux.Lock()
channel.requestedPty = true
channel.mux.Unlock()
}
}
maskedReqs <- req
Expand Down Expand Up @@ -101,15 +102,17 @@ func startHeartbeatingChannel(c ssh.Channel, heartbeat Heartbeat, instanceID str
select {
case <-res.t.C:
res.mux.Lock()
if !res.sawActivity {
if !res.sawActivity || !res.requestedPty {
res.mux.Unlock()
continue
}
res.sawActivity = false
res.mux.Unlock()
heartbeat.SendHeartbeat(instanceID, false)
case <-ctx.Done():
heartbeat.SendHeartbeat(instanceID, true)
if res.requestedPty {
heartbeat.SendHeartbeat(instanceID, true)
}
return
}
}
Expand All @@ -126,6 +129,8 @@ type heartbeatingChannel struct {
t *time.Ticker

cancel context.CancelFunc

requestedPty bool
}

// Read reads up to len(data) bytes from the channel.
Expand Down

0 comments on commit 420c212

Please sign in to comment.