Skip to content

Why is client connection cycling after subscription?

1

Can connect and publish without issue.
Can see subscription registered at the Dashboard
Followed immediately by the disconnect notice and then a continuous connect/disconnect loop

$aws/events/presence/disconnected/AMX_IOT_TEST
August 17, 2021, 14:24:17 (UTC-0700)
{
"clientId": "AMX_IOT_TEST",
"timestamp": 1629235457576,
"eventType": "disconnected",
"clientInitiatedDisconnect": false,
"sessionIdentifier": "c17091a0-452c-4075-868e-5b50356b7636",
"principalIdentifier": "2fab2eec1f3a614028957b190965aaf2985eec1656ca2710837e5e86935b2e55",
"disconnectReason": "CONNECTION_LOST",
"versionNumber": 1323
}
Subscribed
$aws/events/subscriptions/subscribed/AMX_IOT_TEST
August 17, 2021, 14:24:17 (UTC-0700)
{
"clientId": "AMX_IOT_TEST",
"timestamp": 1629235457548,
"eventType": "subscribed",
"sessionIdentifier": "c17091a0-452c-4075-868e-5b50356b7636",
"principalIdentifier": "2fab2eec1f3a614028957b190965aaf2985eec1656ca2710837e5e86935b2e55",
"topics": [
"topic_1"
]
}

Subscribe is as per the PubSub Example

public class TestTopicListener extends AWSIotTopic {

**public TestTopicListener(String topic, AWSIotQos qos) {**  
    **super(topic, qos);**  
**}**  

**@Override**  
**public void onMessage(AWSIotMessage message) {**  
    **System.out.println(System.currentTimeMillis() _ ": <<< " _ message.getStringPayload());**  
**}**  

}
AWSIotTopic subscriber = new TestTopicListener("topic_1", TestTopicQos);
try {
** client.subscribe(subscriber, true);**
} catch (AWSIotException e1) {
** e1.printStackTrace();**
}

The exception handler is never caught
This is the sequence observed on the hardware after subscribe() is invoked

(14:32:35.118):: Aug 17, 2021 2:34:07 PM com.amazonaws.services.iot.client.core.AwsIotConnection onConnectionFailure
(14:32:35.118):: INFO: Connection temporarily lost
(14:32:35.118):: Aug 17, 2021 2:34:07 PM com.amazonaws.services.iot.client.core.AbstractAwsIotClient onConnectionFailure
(14:32:35.118):: INFO: Client connection lost: AMX_IOT_TEST
(14:32:37.988):: Aug 17, 2021 2:34:10 PM com.amazonaws.services.iot.client.core.AwsIotConnection$1 run
(14:32:37.989):: INFO: Connection is being retried
(14:32:38.973):: Aug 17, 2021 2:34:11 PM com.amazonaws.services.iot.client.core.AwsIotConnection onConnectionSuccess
(14:32:38.975):: INFO: Connection successfully established
(14:32:38.984):: Aug 17, 2021 2:34:11 PM com.amazonaws.services.iot.client.core.AbstractAwsIotClient onConnectionSuccess
(14:32:38.985):: INFO: Client connection active: AMX_IOT_TEST

Tried various Policy inputs but same result

{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"iot:Publish",
"iot:RetainPublish"
],
"Resource": [
"arn:aws:iot:us-west-2:xxxxxxx:topic/sdk/test/java",
"arn:aws:iot:us-west-2:xxxxxxx:topic/topic_1",
"arn:aws:iot:us-west-2:xxxxxxx:topic/topic_2",
"arn:aws:iot:us-west-2:xxxxxxx:topic/amx/itg/test/*"
]
},
{
"Effect": "Allow",
"Action": [
"iot:Subscribe"
],
"Resource": [
"arn:aws:iot:us-west-2:xxxxx:topicfilter/sdk/test/java",
"arn:aws:iot:us-west-2:xxxxx:topicfilter/topic_1",
"arn:aws:iot:us-west-2:xxxxx:topicfilter/topic_2",
"arn:aws:iot:us-west-2:xxxxx:topicfilter/amx/itg/test/duet"
]
},
{
"Effect": "Allow",
"Action": [
"iot:Receive"
],
"Resource": [
"arn:aws:iot:us-west-2:xxxxx:topic/topic_1",
"arn:aws:iot:us-west-2:xxxxx:topic/topic_2",
"arn:aws:iot:us-west-2:xxxxx:topic/amx/itg/test/duet"
]
},
{
"Effect": "Allow",
"Action": [
"iot:Connect"
],
"Resource": [,
"arn:aws:iot:us-west-2:xxxxx:client/${iot:Connection.Thing.ThingName}*"
]
}
]
}

Hardware is embedded Jave 1.8
SDK is aws-iot-device-sdk-java

asked 4 years ago491 views
2 Answers
0

Downgraded the MQTT client from 1.2.5 to 1.1.1 (should have read the fine print).

Issue was in AwsIotMqttClientListener with connectionLost() being called in the MQTT client.

answered 4 years ago
0

I had the same issue and spent hours trying to figure it out. Then I read on github that it was due to missing permission. The error code generated is confusing but if you check the logs you'll see that some permission were missing.

https://github.com/aws/aws-iot-device-sdk-python-v2/discussions/329

answered a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.