Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

Commit 3ba357f

Browse files
committed
Add heartbeat
1 parent 6f726cd commit 3ba357f

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

cmd/coder/shell.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"golang.org/x/sys/unix"
1313
"golang.org/x/time/rate"
1414
"golang.org/x/xerrors"
15+
"nhooyr.io/websocket"
1516

1617
"go.coder.com/cli"
1718
"go.coder.com/flog"
@@ -126,6 +127,7 @@ func runCommand(ctx context.Context, envName string, command string, args []stri
126127
if err != nil {
127128
return err
128129
}
130+
go heatbeat(ctx, conn, 15*time.Second)
129131

130132
execer := wsep.RemoteExecer(conn)
131133
process, err := execer.Start(ctx, wsep.Command{
@@ -172,4 +174,21 @@ func runCommand(ctx context.Context, envName string, command string, args []stri
172174
return err
173175
}
174176

177+
func heatbeat(ctx context.Context, c *websocket.Conn, interval time.Duration) {
178+
ticker := time.NewTicker(interval)
179+
defer ticker.Stop()
180+
181+
for {
182+
select {
183+
case <-ctx.Done():
184+
return
185+
case <-ticker.C:
186+
err := c.Ping(ctx)
187+
if err != nil {
188+
flog.Error("failed to ping websocket: %v", err)
189+
}
190+
}
191+
}
192+
}
193+
175194
const sshActivityName = "ssh"

0 commit comments

Comments
 (0)