Send an initial ping so we get online faster in the dashboard

Former-commit-id: 41e4eb24a2
This commit is contained in:
Owen
2026-01-18 15:14:11 -08:00
parent a81c683c66
commit 6d10650e70

View File

@@ -660,16 +660,8 @@ func (c *Client) setupPKCS12TLS() (*tls.Config, error) {
return loadClientCertificate(c.tlsConfig.PKCS12File)
}
// pingMonitor sends pings at a short interval and triggers reconnect on failure
func (c *Client) pingMonitor() {
ticker := time.NewTicker(c.pingInterval)
defer ticker.Stop()
for {
select {
case <-c.done:
return
case <-ticker.C:
// sendPing sends a single ping message
func (c *Client) sendPing() {
if c.isDisconnected || c.conn == nil {
return
}
@@ -679,7 +671,7 @@ func (c *Client) pingMonitor() {
c.processingMux.RUnlock()
if isProcessing {
logger.Debug("websocket: Skipping ping, message is being processed")
continue
return
}
// Send application-level ping with config version
c.configVersionMux.RLock()
@@ -720,6 +712,19 @@ func (c *Client) pingMonitor() {
}
}
}
// pingMonitor sends pings at a short interval and triggers reconnect on failure
func (c *Client) pingMonitor() {
ticker := time.NewTicker(c.pingInterval)
defer ticker.Stop()
for {
select {
case <-c.done:
return
case <-ticker.C:
c.sendPing()
}
}
}
@@ -734,7 +739,12 @@ func (c *Client) StartPingMonitor() {
return
}
c.pingStarted = true
go c.pingMonitor()
// Send an initial ping immediately
go func() {
c.sendPing()
c.pingMonitor()
}()
}
// GetConfigVersion returns the current config version