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
()
| 2462 | // this call will force an immediate reconnect attempt (bypassing |
| 2463 | // the current reconnect delay). |
| 2464 | func (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 |
| 2502 | func (nc *Conn) ConnectedUrl() string { |