Dont start the ping until we are connected

Former-commit-id: 43c8a14fda
This commit is contained in:
Owen
2026-01-17 17:32:01 -08:00
parent a13010c4af
commit 17dc1b0be1
3 changed files with 29 additions and 2 deletions

View File

@@ -100,6 +100,8 @@ type Client struct {
processingMux sync.RWMutex // Protects processingMessage
processingWg sync.WaitGroup // WaitGroup to wait for message processing to complete
getPingData func() map[string]any // Callback to get additional ping data
pingStarted bool // Flag to track if ping monitor has been started
pingStartedMux sync.Mutex // Protects pingStarted
}
type ClientOption func(*Client)
@@ -575,8 +577,14 @@ func (c *Client) establishConnection() error {
c.conn = conn
c.setConnected(true)
// Start the ping monitor
go c.pingMonitor()
// Reset ping started flag on new connection
c.pingStartedMux.Lock()
c.pingStarted = false
c.pingStartedMux.Unlock()
// Note: ping monitor is NOT started here - it will be started when
// StartPingMonitor() is called after registration completes
// Start the read pump with disconnect detection
go c.readPumpWithDisconnectDetection()
@@ -715,6 +723,20 @@ func (c *Client) pingMonitor() {
}
}
// StartPingMonitor starts the ping monitor goroutine.
// This should be called after the client is registered and connected.
// It is safe to call multiple times - only the first call will start the monitor.
func (c *Client) StartPingMonitor() {
c.pingStartedMux.Lock()
defer c.pingStartedMux.Unlock()
if c.pingStarted {
return
}
c.pingStarted = true
go c.pingMonitor()
}
// GetConfigVersion returns the current config version
func (c *Client) GetConfigVersion() int {
c.configVersionMux.RLock()