I'm working with an MQTT broker that allows only a single connection per user at a time. Currently, connecting is implemented like this:
timeout := 30 * time.Second
if t := paho.Connect(); !t.WaitTimeout(timeout) {
return errors.New("connect timeout")
} else if err := t.Error(); err != nil {
return fmt.Errorf("connect: %w", err)
}
defer paho.Disconnect(1000)
From the docs, it's not clear, if a Disconnect is also required in case of the connection timeout in order to clean up any dangling go routines? I wouldn't expect it to be required in case of error.