Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

auto-reconnect not working for initial connection attempt. #77

Closed
databus23 opened this issue Feb 7, 2017 · 4 comments
Closed

auto-reconnect not working for initial connection attempt. #77

databus23 opened this issue Feb 7, 2017 · 4 comments

Comments

@databus23
Copy link
Contributor

This is a follow up on #52, maybe, sort of, I don't know...
I might be missing something here, it seems to me that the re-connect logic is not kicking in for the initial connection to the broker.
Only when the initial connection is successful, the client goes into a reconnect loop whenever the connection is lost.

Is this by design? If so this would mean users of the client would need to implement a second reconnect logic outside of the client to cover all cases. Otherwise they are stuck with disconnected client when the broker happened to be unreachable when the client starts up.

@databus23 databus23 changed the title auto-reconnect not working for initial connection re-attempt. auto-reconnect not working for initial connection attempt. Feb 7, 2017
@kylycht
Copy link

kylycht commented Feb 22, 2017

@databus23 initial connection can be inside a loop

so something like

retry := time.NewTicker(5 * time.Second)
RetryLoop:
	for {
		select {
		case <-retry.C:
			if token := client.Connect(); token.Wait() && token.Error() != nil {
				//handle error
			} else {
				retry.Stop()
				break RetryLoop
			}
		}
	}

this will try to connect every 5 seconds, once connection is established it will break out the loop
if connection is lost, re-connect should kick in
hope this helps to solve your problem

@alsm
Copy link
Contributor

alsm commented Mar 22, 2017

This is working as designed, in that there was no intention to do automatic reattempts to connect on initial connection. If you have specified multiple servers to connect to the client will attempt to connect to each in turn if it fails to connect to the previous one, and if we are in automatic version mode we will attempt to connect at version 3 if version 4 was unsuccessful.
When I say as designed though, there was no explicit thought that it should not, at some point, do automatic connection reattempts at initial connection, it just wasn't written that way.

@alsm alsm closed this as completed Mar 22, 2017
@masc3d
Copy link

masc3d commented May 12, 2017

I don't see how this is a good reason to close this.
The reconnection feature is incomplete and inconsistent this way.

@huntc
Copy link

huntc commented Mar 14, 2018

I'd like to add that I got caught out majorly on this. I'd assert that most times, there's just one URI to connect - particularly given when service discovery is in place. The distinction between an initial connection and retrying a connection is, for me at least, unintuitive and diminishes the usefulness of auto-reconnect.

huntc added a commit to huntc/alpakka that referenced this issue Mar 14, 2018
Unfortunately the Paho library [doesn't support the management of initial connects failing by design](eclipse/paho.mqtt.golang#77). This PR warns the reader.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants