ESP8266 Arduino

Yeah, the ESP8266 Arduino support is under development.
The reconnection logic is flaky.

The -9 you’re seeing is EBADF, but that comes from the connect() implementation on top of the low-level lwip API. What happens is that Lwip tcp_connect() call fails.

Bear with us, ESP8266 support will improve soon.
We’ve pushed version 1.0.27 which should fix the connection issue.
However, TLS, OTA and filesystem support are still pending.
Remote control (ability to specify custom functions and call them), MQTT, shadow should work just fine.

Do you have a specific project on ESP8266 or just experimenting?