net: mqtt: Reset client state before notifying MQTT_EVT_DISCONNECT
net: mqtt: Reset client state before notifying MQTT_EVT_DISCONNECT

MQTT client state is protected using mutex. That mutex however is
temporarily unlocked when calling event callbacks. This means that in
client_disconnect() transport can already be disconnected, but without
marking it as such in client->internal.state.

When mutex is unlocked in event_notify() function, then there are two
possible paths of failure:

1) First possibility is when RX and TX are called from two separate
   threads, so that the other thread gets resumed and functions like
   verify_tx_state() (e.g. in mqtt_publish()) allow to continue
   communication over disconnected medium.
2) Another possibility is that user calls mqtt_abort() or
   mqtt_disconnect() in event handler.

In both cases MQTT library tries to send or receive data, possibly
followed by second close() of underlying file descriptor.

Prevent using disconnected transport by clearing MQTT client state right
after calling mqtt_transport_disconnect(), without releasing mutex, even
for a while.

Signed-off-by: Marcin Niestroj <63506c06cfbc47ace147db1702f6e751f5ac2132@grinn-global.com>

Vudentz/zephyr,finikorg/zephyr,galak/zephyr,zephyrproject-rtos/zephyr,nashif/zephyr,Vudentz/zephyr,finikorg/zephyr,nashif/zephyr,nashif/zephyr,galak/zephyr,finikorg/zephyr,finikorg/zephyr,nashif/zephyr,galak/zephyr,Vudentz/zephyr,galak/zephyr,zephyrproject-rtos/zephyr,nashif/zephyr,zephyrproject-rtos/zephyr,Vudentz/zephyr,zephyrproject-rtos/zephyr,finikorg/zephyr,Vudentz/zephyr,galak/zephyr,zephyrproject-rtos/zephyr,Vudentz/zephyr