Been scratching my head over this one for a few hours..
I am testing out the AWS IoT library in version 1.3.1 of nrf Connect SDK. Connect, subscribe, and ping are all working correctly as evidenced by the logs. However, after one minute the socket connection always closes. In this example I have the keep-alive interval set to 20s to show successful PING and PINGRESP messages but this happens regardless of the configured keep-alive internal.
*** Booting Zephyr OS build v2.3.0-rc1-ncs1 ***
Application Started
modem_key_mgmt_delete(1, 0) => result=0
modem_key_mgmt_delete(1, 1) => result=0
modem_key_mgmt_delete(1, 2) => result=0
modem_key_mgmt_write => result=0
modem_key_mgmt_write => result=0
modem_key_mgmt_write => result=0
LTE Link Connecting ...
LTE Link Connected!
[00:00:24.241,455] <dbg> aws_iot.broker_init: IPv4 Address found 18.219.99.192
[00:00:28.221,923] <dbg> aws_iot.mqtt_evt_handler: MQTT client connected!
[00:00:28.229,492] <dbg> aws_iot.topic_subscribe: Subscribing to application topic: test
AWS IoT connected
AWS IoT ready
[00:00:28.541,900] <dbg> aws_iot.mqtt_evt_handler: MQTT_EVT_SUBACK: id = 7520 result = 0
Pinging broker
[00:00:48.237,060] <dbg> aws_iot.mqtt_evt_handler: MQTT_EVT_PINGRESP: result = 0
Pinging broker
[00:01:07.919,677] <dbg> aws_iot.mqtt_evt_handler: MQTT_EVT_PINGRESP: result = 0
[00:01:26.500,427] <dbg> aws_iot.mqtt_evt_handler: MQTT_EVT_DISCONNECT: result = -128
AWS IoT disconnected
Socket error: POLLNVAL
The AWS IoT socket was unexpectedly closed.
Cloudwatch logs show nothing more than a successful connect and disconnect:
EVENT:MQTT Client Connect MESSAGE: IpAddress: <redacted> SourcePort: 61993
EVENT:MQTT Client Disconnect MESSAGE: IpAddress: <redacted> SourcePort: 61993
The polling thread option has not been added in v1.3.1 but I am running a similar thread in main.c