What's your scan time? For Gmail, I found that the process requires about 1.85 to 1.90 seconds of CPU time, and with the login timing out on Google's end after about 9 seconds, that means you must dedicate at least 21% of CPU time to logging in or it will time out. Email has a 1666 us/scan timeslice, so I have to have a scan time below 6.2ms (when not logging in) to log in. I don't know if MQTT has a similar timeslice number, or it might even be the same one, but try again with a program that has nothing in it but the MQTT. Then increase the scan time gradually and see it that makes it fail at some point.