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

This commit is contained in:
Owen
2026-01-18 15:14:11 -08:00
parent 592a0d60c6
commit 41e4eb24a2

View File

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