Connection interrupted: 5134: The connection was closed unexpectedly. #439
-
In my Java/Maven project I am using the following dependency, in attempt to publish some data to AWS MQTT:
I have copied the code from the example to try it out. It looks like I am successfully connecting to AWS MQTT initially, but the connection is dropped almost immediately after opening. Then it is restored with new fresh session, but then suddenly dropped again. This sequence repeats itself over and over. Any attempt to publish the data using the connection results in the following exception thrown: Trace: java.util.concurrent.ExecutionException: software.amazon.awssdk.crt.mqtt.MqttException: Old requests from the previous session are cancelled, and offline request will not be accept. I have tried various things and now I ran out of ideas of what to try next. Anyone can suggest something to try? Here is the code that I use for the above:
Following is the Log I am getting from it: ERROR > Failed to publish data to MQTT. Retries = 10 Error: java.util.concurrent.ExecutionException: software.amazon.awssdk.crt.mqtt.MqttException: Old requests from the previous session are cancelled, and offline request will not be accept. Trace: java.util.concurrent.ExecutionException: software.amazon.awssdk.crt.mqtt.MqttException: Old requests from the previous session are cancelled, and offline request will not be accept. Caused by: software.amazon.awssdk.crt.mqtt.MqttException: Old requests from the previous session are cancelled, and offline request will not be accept. ERROR > Failed to publish data to MQTT. Retries = 9 Error: java.util.concurrent.ExecutionException: software.amazon.awssdk.crt.mqtt.MqttException: Old requests from the previous session are cancelled, and offline request will not be accept. Trace: java.util.concurrent.ExecutionException: software.amazon.awssdk.crt.mqtt.MqttException: Old requests from the previous session are cancelled, and offline request will not be accept. Caused by: software.amazon.awssdk.crt.mqtt.MqttException: Old requests from the previous session are cancelled, and offline request will not be accept. Connection resumed: clean session Trace: java.util.concurrent.ExecutionException: software.amazon.awssdk.crt.mqtt.MqttException: Old requests from the previous session are cancelled, and offline request will not be accept. ERROR > Failed to publish data to MQTT. Retries = 7 Error: java.util.concurrent.ExecutionException: software.amazon.awssdk.crt.mqtt.MqttException: Old requests from the previous session are cancelled, and offline request will not be accept. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 4 replies
-
Answer: |
Beta Was this translation helpful? Give feedback.
-
Hello! Reopening this discussion to make it searchable. |
Beta Was this translation helpful? Give feedback.
-
See below logs.
If it can help you to suggest solution.
[DEBUG] [2024-08-21T11:11:58Z] [00000002863cf000] [tls-handler] - static: certificate and key have been set, setting them up now.
[INFO] [2024-08-21T11:11:58Z] [00000002863cf000] [pki-utils] - static: certificate has an existing certificate-key pair that was previously imported into the Keychain. Using key from Keychain instead of the one provided.
[DEBUG] [2024-08-21T11:11:58Z] [00000002863cf000] [tls-handler] - static: loading custom CA file.
[DEBUG] [2024-08-21T11:11:58Z] [00000002863cf000] [mqtt-client] - client=0x1146295f0: Initalizing MQTT client
[DEBUG] [2024-08-21T11:11:58Z] [00000002863cf000] [channel-bootstrap] - id=0x1259fdb90: acquiring bootstrap reference
[DEBUG] [2024-08-21T11:11:58Z] [00000002863cf000] [mqtt-client] - id=0x117250600: Creating new mqtt 311 connection
[DEBUG] [2024-08-21T11:11:58Z] [00000002863cf000] [mqtt-topic-tree] - tree=0x117250918: Creating new topic tree
[DEBUG] [2024-08-21T11:11:58Z] [00000002863cf000] [mqtt-client] - mqtt_jni_connection acquire, ref count now = 2
[DEBUG] [2024-08-21T11:11:58Z] [00000002863cf000] [mqtt-client] - id=0x117250600: Begin connecting process, switch state to CONNECTING.
[INFO] [2024-08-21T11:11:58Z] [00000002863cf000] [mqtt-client] - id=0x117250600: using ping timeout of 3000000000 ns
[DEBUG] [2024-08-21T11:11:58Z] [00000002863cf000] [channel-bootstrap] - id=0x1259fdb90: acquiring bootstrap reference
[DEBUG] [2024-08-21T11:11:58Z] [00000002863cf000] [dns] - id=0x1259fe1e0: Host resolution requested for a1bjx53wzzzgiu-ats.iot.ap-south-1.amazonaws.com
[DEBUG] [2024-08-21T11:11:58Z] [00000002863cf000] [dns] - id=0x1259fe1e0: cached entries found for a1bjx53wzzzgiu-ats.iot.ap-south-1.amazonaws.com returning to caller.
[DEBUG] [2024-08-21T11:11:58Z] [0000000286343000] [socket] - id=0x12419a500 fd=210: initializing with domain 1 and type 0
[DEBUG] [2024-08-21T11:11:58Z] [0000000286343000] [socket] - id=0x12419a500 fd=210: setting socket options to: keep-alive 0, keep idle 0, keep-alive interval 0, keep-alive probe count 0.
[DEBUG] [2024-08-21T11:11:58Z] [0000000286343000] [socket] - id=0x12419a500 fd=210: beginning connect.
[DEBUG] [2024-08-21T11:11:58Z] [0000000286343000] [socket] - id=0x12419a500 fd=210: connecting to endpoint 2406:da00:a000::dea:55ce:8883.
[DEBUG] [2024-08-21T11:11:58Z] [0000000286343000] [socket] - id=0x12419a500 fd=210: connect failed with error code 65.
[INFO] [2024-08-21T11:11:58Z] [0000000286343000] [dns] - id=0x1259fe1e0: recording failure for record 2406:da00:a000::dea:55ce for a1bjx53wzzzgiu-ats.iot.ap-south-1.amazonaws.com, moving to bad list
[DEBUG] [2024-08-21T11:11:58Z] [0000000286343000] [dns] - static: purging address 2406:da00:a000::dea:55ce for host a1bjx53wzzzgiu-ats.iot.ap-south-1.amazonaws.com from the cache due to cache eviction or shutdown
[DEBUG] [2024-08-21T11:11:58Z] [0000000286343000] [socket] - id=0x12419a500 fd=210: is still open, closing...
[DEBUG] [2024-08-21T11:11:58Z] [0000000286343000] [socket] - id=0x12419a500 fd=210: closing
[DEBUG] [2024-08-21T11:11:58Z] [0000000286343000] [channel-bootstrap] - id=0x1259fdb90: Socket connect attempt 1/2 failed with error 1049. More attempts ongoing...
[DEBUG] [2024-08-21T11:11:58Z] [0000000286343000] [socket] - id=0x12419a500 fd=210: initializing with domain 0 and type 0
[DEBUG] [2024-08-21T11:11:58Z] [0000000286343000] [socket] - id=0x12419a500 fd=210: setting socket options to: keep-alive 0, keep idle 0, keep-alive interval 0, keep-alive probe count 0.
[DEBUG] [2024-08-21T11:11:58Z] [0000000286343000] [socket] - id=0x12419a500 fd=210: beginning connect.
[DEBUG] [2024-08-21T11:11:58Z] [0000000286343000] [socket] - id=0x12419a500 fd=210: connecting to endpoint 43.204.118.106:8883.
[INFO] [2024-08-21T11:11:58Z] [0000000286343000] [socket] - id=0x12419a500 fd=210: connection success
[DEBUG] [2024-08-21T11:11:58Z] [0000000286343000] [socket] - id=0x12419a500 fd=210: assigning to event loop 0x1259fc4f0
[DEBUG] [2024-08-21T11:11:58Z] [0000000286343000] [channel-bootstrap] - id=0x1259fdb90: client connection on socket 0x12419a500 completed with error 0.
[DEBUG] [2024-08-21T11:11:58Z] [0000000286343000] [channel] - id=0x1472205e0: Beginning creation and setup of new channel.
[DEBUG] [2024-08-21T11:11:58Z] [0000000286343000] [channel] - id=0x1472205e0: setup complete, notifying caller.
[DEBUG] [2024-08-21T11:11:58Z] [0000000286343000] [channel] - id=0x1472205e0: no message pool is currently stored in the event-loop local storage, adding 0x147231c70 with max message size 262144, message count 4, with 4 small blocks of 128 bytes.
[DEBUG] [2024-08-21T11:11:58Z] [0000000286343000] [channel-bootstrap] - id=0x1259fdb90: channel 0x1472205e0 setup succeeded: bootstrapping.
[DEBUG] [2024-08-21T11:11:58Z] [0000000286343000] [socket-handler] - id=0x11448c340: Socket handler created with max_read_size of 262144
[DEBUG] [2024-08-21T11:11:58Z] [0000000286343000] [tls-handler] - id=0x147231dc0: negotiation succeeded
[DEBUG] [2024-08-21T11:11:58Z] [0000000286343000] [tls-handler] - id=0x147231dc0: Remote Server Name: a1bjx53wzzzgiu-ats.iot.ap-south-1.amazonaws.com
[DEBUG] [2024-08-21T11:11:58Z] [0000000286343000] [channel-bootstrap] - id=0x1259fdb90: tls negotiation result 0 on channel 0x1472205e0
[DEBUG] [2024-08-21T11:11:58Z] [0000000286343000] [mqtt-client] - id=0x117250600: Connection successfully opened, sending CONNECT packet
[DEBUG] [2024-08-21T11:11:58Z] [0000000286343000] [mqtt-client] - id=0x117250600: MQTT Connection initializing CONNECT packet for client-id 'iotconsoleTESTINGanandok'
[DEBUG] [2024-08-21T11:11:58Z] [0000000286343000] [mqtt-client] - id=0x117250600: Adding username ?SDK=JavaV2&Version=0.30 to connection
[DEBUG] [2024-08-21T11:11:58Z] [0000000286343000] [mqtt-client] - id=0x117250600: CONNACK received
[DEBUG] [2024-08-21T11:11:58Z] [0000000286343000] [mqtt-client] - id=0x117250600: connection was accepted, switch state from 0 to CONNECTED.
[DEBUG] [2024-08-21T11:11:58Z] [0000000286343000] [aws-c-common] - s_aws_jni_get_thread_env returned detached, attaching
[DEBUG] [2024-08-21T11:11:58Z] [0000000286343000] [mqtt-client] - mqtt_jni_connection release, ref count now = 1
Connected to existing session!
[DEBUG] [2024-08-21T11:11:58Z] [00000002863cf000] [mqtt-client] - id=0x117250600: Starting subscribe 1 on topic Devices/M2C/#
[DEBUG] [2024-08-21T11:11:58Z] [0000000286343000] [mqtt-topic-tree] - tree=0x117250918: Inserting topic filter Devices/M2C/# into topic tree
[DEBUG] [2024-08-21T11:11:58Z] [0000000286343000] [mqtt-client] - id=0x117250600: received a SUBACK
[DEBUG] [2024-08-21T11:11:58Z] [0000000286343000] [mqtt-client] - id=0x117250600: Subscribe 1 completed with error code 0
[DEBUG] [2024-08-21T11:11:58Z] [00000002863cf000] [mqtt-client] - id=0x12531a800: disconnect finished, switch state to DISCONNECTED.
[DEBUG] [2024-08-21T11:11:58Z] [00000002863cf000] [mqtt-client] - id=0x12531a800: Last refcount on connection has been released, start destroying the connection.
[DEBUG] [2024-08-21T11:11:58Z] [00000002863cf000] [mqtt-client] - id=0x12531a800: Destroying connection
[DEBUG] [2024-08-21T11:11:58Z] [00000002863cf000] [mqtt-topic-tree] - tree=0x12531ab18: Cleaning up topic tree
[DEBUG] [2024-08-21T11:11:58Z] [00000002863cf000] [mqtt-client] - client=0x1144b2bc0: Cleaning up MQTT client
[DEBUG] [2024-08-21T11:11:58Z] [00000002863cf000] [channel-bootstrap] - id=0x1259fdb90: releasing bootstrap reference
[DEBUG] [2024-08-21T11:11:58Z] [00000002863cf000] [channel] - id=0x1241a3fb0: destroying channel.
[DEBUG] [2024-08-21T11:11:58Z] [00000002863cf000] [channel-bootstrap] - id=0x1259fdb90: releasing bootstrap reference
***@***.***
> 1
[DEBUG] [2024-08-21T11:12:03Z] [000000029061f000] [mqtt-client] - id=0x117250600: user called disconnect.
[DEBUG] [2024-08-21T11:12:03Z] [000000029061f000] [mqtt-client] - id=0x117250600: User requests disconnecting, switch state to DISCONNECTING.
> 2
[DEBUG] [2024-08-21T11:12:03Z] [000000029061f000] [mqtt-client] - id=0x117250600: Closing connection
[DEBUG] [2024-08-21T11:12:03Z] [000000029061f000] [mqtt-client] - id=0x117250600: user called disconnect.
[ERROR] [2024-08-21T11:12:03Z] [000000029061f000] [mqtt-client] - id=0x117250600: Connection is not open, and may not be closed
[DEBUG] [2024-08-21T11:12:03Z] [000000029061f000] [mqtt-client] - Client disconnect failed. Release the client connection.
[DEBUG] [2024-08-21T11:12:03Z] [000000029061f000] [mqtt-client] - mqtt_jni_connection shutdown complete, releasing references
> 3
closed
[DEBUG] [2024-08-21T11:12:03Z] [0000000286343000] [channel] - id=0x1472205e0: beginning shutdown process
[DEBUG] [2024-08-21T11:12:03Z] [0000000286343000] [channel] - id=0x1472205e0: handler 0x11448c340 shutdown in read dir completed.
[DEBUG] [2024-08-21T11:12:03Z] [0000000286343000] [tls-handler] - id=0x147231dc0: shutting down read direction with error 0. Flushing queues.
[DEBUG] [2024-08-21T11:12:03Z] [0000000286343000] [channel] - id=0x1472205e0: handler 0x147231dc0 shutdown in read dir completed.
[DEBUG] [2024-08-21T11:12:03Z] [0000000286343000] [channel] - id=0x1472205e0: handler 0x117250638 shutdown in read dir completed.
[INFO] [2024-08-21T11:12:03Z] [0000000286343000] [mqtt-client] - id=0x117250600: sending disconnect message as part of graceful shutdown.
[DEBUG] [2024-08-21T11:12:03Z] [0000000286343000] [channel] - id=0x1472205e0: handler 0x117250638 shutdown in write dir completed.
[DEBUG] [2024-08-21T11:12:03Z] [0000000286343000] [channel] - id=0x1472205e0: handler 0x147231dc0 shutdown in write dir completed.
[DEBUG] [2024-08-21T11:12:03Z] [0000000286343000] [socket] - id=0x12419a500 fd=210: closing
[DEBUG] [2024-08-21T11:12:03Z] [0000000286343000] [channel] - id=0x1472205e0: handler 0x11448c340 shutdown in write dir completed.
[DEBUG] [2024-08-21T11:12:03Z] [0000000286343000] [channel] - id=0x1472205e0: during shutdown, canceling task 0x147231df0
[DEBUG] [2024-08-21T11:12:03Z] [0000000286343000] [channel] - id=0x1472205e0: during shutdown, canceling task 0x117250858
[DEBUG] [2024-08-21T11:12:03Z] [0000000286343000] [channel-bootstrap] - id=0x1259fdb90: channel 0x1472205e0 shutdown with error 0.
[DEBUG] [2024-08-21T11:12:03Z] [0000000286343000] [mqtt-client] - id=0x117250600: disconnect finished, switch state to DISCONNECTED.
[DEBUG] [2024-08-21T11:12:03Z] [0000000286343000] [mqtt-client] - id=0x117250600: Disconnect completed, clearing request queue and calling callback
[DEBUG] [2024-08-21T11:12:03Z] [0000000286343000] [mqtt-client] - id=0x117250600: Last refcount on connection has been released, start destroying the connection.
[DEBUG] [2024-08-21T11:12:03Z] [0000000286343000] [mqtt-client] - id=0x117250600: Destroying connection
[DEBUG] [2024-08-21T11:12:03Z] [0000000286343000] [mqtt-topic-tree] - tree=0x117250918: Cleaning up topic tree
[DEBUG] [2024-08-21T11:12:03Z] [0000000286343000] [channel] - id=0x1472205e0: destroying channel.
[DEBUG] [2024-08-21T11:12:03Z] [0000000286343000] [channel-bootstrap] - id=0x1259fdb90: releasing bootstrap reference
From: Joseph Klix ***@***.***>
Date: Monday, 19 August 2024 at 10:27 PM
To: aws/aws-iot-device-sdk-java-v2 ***@***.***>
Cc: Anand Mahajan ***@***.***>, Comment ***@***.***>
Subject: Re: [aws/aws-iot-device-sdk-java-v2] Connection interrupted: 5134: The connection was closed unexpectedly. (Discussion #439)
I would suggest looking at the CloudWatch logs<https://docs.aws.amazon.com/iot/latest/developerguide/cloud-watch-logs.html> to see what the reason for the disconnect is on the server side. If you still can't figure out what is causing your connections to close unexpectedly I would suggest opening a new discussion that includes details about your situation.
—
Reply to this email directly, view it on GitHub<#439 (reply in thread)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AAJJWM6UVQCMRXZMFCOZYSDZSIPWZAVCNFSM6AAAAABMVMPXECVHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTAMZYGY2TSNQ>.
You are receiving this because you commented.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
Answer:
Hello @Gnumster ,
Thank you very much for your submission. Could you please provide the trace log associated with the behavior?
I was also wondering if you have activated your certificate in the IoT console? (See : https://docs.aws.amazon.com/iot/latest/developerguide/activate-or-deactivate-device-cert.html) and also what permissions you are using for the IAM policy? My first guess would be that you might have not activated your certificate as similar behavior has been reported when not activating certificate (see)
Best regards,
Yasmine