yosssi / gmq

Pure Go MQTT Client
MIT License
346 stars 46 forks source link

Disconnected by AWS IoT MQTT Broker #9

Open dwarburt opened 6 years ago

dwarburt commented 6 years ago

Dropping the TLS example almost line-by-line into a test program for AWS IoT caused the server to close the connection when the first subscribe packet is sent.

When I put a time.Sleep(time.Second) in between the cli.Connect and cli.Subscribe calls, then it works just fine. It seems that AWS will close the connection if the subscribe comes too quickly. It seems like the key is to wait until that CONNACK packet is received before continuing with the other messages.

Can we add some sort of event or callback for CONNACK? Like a ConnectedHandler or maybe a buffered channel that sends connection lifecycle events that the main program can read?

skx commented 6 years ago

FWIW I see the same thing with a simple client that does three things:

If I disconnect "too quickly" the message is never received. I've had to add time.Sleep() calls into the middle of the steps which is horrid.