Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions internal/cmd/ocean/spark_connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,9 @@ func handleSocketConnection(ctx context.Context, conn net.Conn, wsConn *websocke
return fromUpstream(conn, wsConn)
})

// Send websocket ping periodically to keep connection alive
g.Go(func() error { return sendPing(ctx, wsConn) })

return g.Wait()
}

Expand Down Expand Up @@ -315,3 +318,19 @@ func toUpstream(downstream io.Writer, upstream *websocket.Conn) error {

return nil
}

func sendPing(ctx context.Context, wsConn *websocket.Conn) error {
ticker := time.NewTicker(5 * time.Second)
defer ticker.Stop()

for {
select {
case <-ctx.Done():
return nil
case <-ticker.C:
if err := wsConn.WriteMessage(websocket.PingMessage, nil); err != nil {
return err
}
}
}
}