nats-io / stan.go

NATS Streaming System
https://nats.io
Apache License 2.0
706 stars 117 forks source link

Return promise connection with RECONNECTING status instead error #352

Closed amelkikh closed 3 years ago

amelkikh commented 3 years ago

Hi! In version 1.11 of Nats the RetryOnFailedConnect option appeared. This allows to get a connection to the Nats with status RECONNECTING despite the unavailability of the connection at the time of connection. This creates some problem for the initialization of the Stan. Is it possible to replace the ErrBadConnection connection error with the ConnectTimeout option? To make the client wait for reconnection to Nats on initial connection?

if c.nc == nil {
  ...
} else if !c.nc.IsConnected() {
  // Bail if the custom NATS connection is disconnected
  return nil, ErrBadConnection
}

Thanks!

kozlovic commented 3 years ago

Is it possible to replace the ErrBadConnection connection error with the ConnectTimeout option? To make the client wait for reconnection to Nats on initial connection?

No, this would not make the STAN client automatically issue the connect (which is a request/reply with the STAN server) when the NATS connection is ready. Since you provide the NATS connection, then you could chose to set a reconnect handler and then issue the STAN connect (at least for the very first connect, which you need to distinguish from a later disconnect followed by a reconnect).