MCPcopy
hub / github.com/nats-io/nats.go / ForceReconnect

Method ForceReconnect

nats.go:2464–2499  ·  view source on GitHub ↗

ForceReconnect forces a reconnect attempt to the server. This is a non-blocking call and will start the reconnect process without waiting for it to complete. If the connection is already in the process of reconnecting, this call will force an immediate reconnect attempt (bypassing the current recon

()

Source from the content-addressed store, hash-verified

2462// this call will force an immediate reconnect attempt (bypassing
2463// the current reconnect delay).
2464func (nc *Conn) ForceReconnect() error {
2465 nc.mu.Lock()
2466 defer nc.mu.Unlock()
2467
2468 if nc.isClosed() {
2469 return ErrConnectionClosed
2470 }
2471 if nc.isReconnecting() {
2472 // if we're already reconnecting, force a reconnect attempt
2473 // even if we're in the middle of a backoff
2474 if nc.rqch != nil {
2475 close(nc.rqch)
2476 nc.rqch = nil
2477 }
2478 return nil
2479 }
2480
2481 // Clear any queued pongs
2482 nc.clearPendingFlushCalls()
2483
2484 // Clear any queued and blocking requests.
2485 nc.clearPendingRequestCalls()
2486
2487 // Stop ping timer if set.
2488 nc.stopPingTimer()
2489
2490 // flush any pending data and switch to pending mode to buffer new outgoing
2491 // data until we reconnect and can flush it.
2492 nc.bw.flush()
2493 nc.bw.switchToPending()
2494 nc.conn.Close()
2495
2496 nc.changeConnStatus(RECONNECTING)
2497 go nc.doReconnect(nil, true)
2498 return nil
2499}
2500
2501// ConnectedUrl reports the connected server's URL
2502func (nc *Conn) ConnectedUrl() string {

Calls 10

isClosedMethod · 0.95
isReconnectingMethod · 0.95
stopPingTimerMethod · 0.95
changeConnStatusMethod · 0.95
doReconnectMethod · 0.95
flushMethod · 0.80
switchToPendingMethod · 0.80
CloseMethod · 0.45