mirror of
https://github.com/fosrl/olm.git
synced 2026-02-08 05:56:41 +00:00
Dont start the ping until we are connected
This commit is contained in:
@@ -198,6 +198,9 @@ func (o *Olm) handleConnect(msg websocket.WSMessage) {
|
|||||||
|
|
||||||
o.connected = true
|
o.connected = true
|
||||||
|
|
||||||
|
// Start ping monitor now that we are registered and connected
|
||||||
|
o.websocket.StartPingMonitor()
|
||||||
|
|
||||||
// Invoke onConnected callback if configured
|
// Invoke onConnected callback if configured
|
||||||
if o.olmConfig.OnConnected != nil {
|
if o.olmConfig.OnConnected != nil {
|
||||||
go o.olmConfig.OnConnected()
|
go o.olmConfig.OnConnected()
|
||||||
|
|||||||
@@ -362,6 +362,8 @@ func (o *Olm) StartTunnel(config TunnelConfig) {
|
|||||||
|
|
||||||
if o.connected {
|
if o.connected {
|
||||||
logger.Debug("Already connected, skipping registration")
|
logger.Debug("Already connected, skipping registration")
|
||||||
|
// Restart ping monitor on reconnect since the old one would have exited
|
||||||
|
o.websocket.StartPingMonitor()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -100,6 +100,8 @@ type Client struct {
|
|||||||
processingMux sync.RWMutex // Protects processingMessage
|
processingMux sync.RWMutex // Protects processingMessage
|
||||||
processingWg sync.WaitGroup // WaitGroup to wait for message processing to complete
|
processingWg sync.WaitGroup // WaitGroup to wait for message processing to complete
|
||||||
getPingData func() map[string]any // Callback to get additional ping data
|
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)
|
type ClientOption func(*Client)
|
||||||
@@ -575,8 +577,14 @@ func (c *Client) establishConnection() error {
|
|||||||
c.conn = conn
|
c.conn = conn
|
||||||
c.setConnected(true)
|
c.setConnected(true)
|
||||||
|
|
||||||
// Start the ping monitor
|
// Reset ping started flag on new connection
|
||||||
go c.pingMonitor()
|
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
|
// Start the read pump with disconnect detection
|
||||||
go c.readPumpWithDisconnectDetection()
|
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
|
// GetConfigVersion returns the current config version
|
||||||
func (c *Client) GetConfigVersion() int {
|
func (c *Client) GetConfigVersion() int {
|
||||||
c.configVersionMux.RLock()
|
c.configVersionMux.RLock()
|
||||||
|
|||||||
Reference in New Issue
Block a user