-
Notifications
You must be signed in to change notification settings - Fork 37
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
Add a delay before reconnecting to MQTT #161
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -99,6 +99,17 @@ func NewMQTTTransport(clientID string, brokers []string, tlsConfig *tls.Config) | |
t.events <- TransporterEventDisconnected | ||
}) | ||
|
||
opts.SetReconnectingHandler(func(c mqtt.Client, co *mqtt.ClientOptions) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yea, the MQTT client package does the backing off itself. We just get a handler that's called before the reconnect attempt happens. I don't think the value is exported by the package at all. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just noticed that the delay is printed, when |
||
if config.DefaultConfig.MQTTReconnectDelay > 0 { | ||
log.Infof( | ||
"delaying for %v before reconnecting...", | ||
config.DefaultConfig.MQTTReconnectDelay, | ||
) | ||
time.Sleep(config.DefaultConfig.MQTTReconnectDelay) | ||
} | ||
log.Debugf("reconnecting to broker: %v", co.Servers) | ||
}) | ||
|
||
data, err := json.Marshal(&yggdrasil.ConnectionStatus{ | ||
Type: yggdrasil.MessageTypeConnectionStatus, | ||
MessageID: uuid.New().String(), | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is pretty confusing that you cannot use
--mqtt-reconnect-delay
with simple numeric value. I was expecting that it should work and value would be considered in seconds.I think that we should emphasize in
Usage:
that argument should be something like10s
(not only10
or"10"
).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that we should also improve
Usage
text of other occurrences ofDurationFlag
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Internally, the
DurationFlag
usestime.ParseDuration
to parse the value. That function does not make assumptions about default duration unit if the unit is omitted. The error returned by an invalid value for the flag does not make a suggestion about how to specify a valid format. That error comes from the cli package though; we can't change it.These are hidden flags though; their
Usage
won't be visible to a user in the--help
output. I changed the hidden value totrue
to see what the usage text looks like:The default value there hints at using a duration unit, so if we do ever make these visible flags, the usage does suggest to the user how to specify a correct value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, you are right, when the flag is hidden, then the usage could not visible.