Share via

MQTT socket going into close wait state

Anoop Chandran 25 Reputation points
2023-06-07T11:04:17.7566667+00:00

Hi,

I am currently working on the iot-middleware-freertos-samples to implement MQTT.

After establishing the MQTTS connection and subscribing to the required topics I am trying to send telemetry data to the IoT hub but after some time the MQTT socket is going to a close wait state.

I am using the API " AzureIoTHubClient_SendTelemetry" to send the payload.

After sending the telemetry data I am also calling the function "AzureIoTHubClient_ProcessLoop" for receiving any responses.

Can you please tell me how I can avoid this close wait state?

I have set the keep-alive time out as 5 min and Iam sending data every 1min.

Regards

Anoop

Azure IoT Hub
Azure IoT Hub

An Azure service that enables bidirectional communication between internet of things (IoT) devices and applications.


Answer accepted by question author

LeelaRajeshSayana-MSFT 17,871 Reputation points Moderator
2023-06-07T17:26:10.6966667+00:00

Hi @Anoop Chandran Greetings! Welcome to Microsoft Q&A forum. Thank you for posting the question here. The close wait state indicates that the socket is waiting for the remote end to close the connection. It is possible that the Azure IoT Hub is not closing the connection after receiving the telemetry data.

I appreciate it if you can check the Azure IoT Hub logs to see if there are any errors or warnings related to the connection. Also, please try increasing the sampleazureiotPROCESS_LOOP_TIMEOUT_MS value to give more time for the connection to close.

Let me know if this helps.

Was this answer helpful?

0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.