Skip to content

Cannot connect to MQTT and publish message #134

@volphy

Description

@volphy

Confirm by changing [ ] to [x] below to ensure that it's a bug:

Describe the bug
I cannot connect to the following AWS IoT endpoint:
<prefix>-ats.iot.eu-west-2.amazonaws.com
using device certificate (ECC, P-256). I use mutual authentication (mTLS).
This certificate has been issued by a CA that is under my control. Both the CA and this certificate were registered to the AWS IoT Core before running any tests.
An attempt to publish an MQTT message fails with the following exception:

Exception in thread "main" 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.
	at java.base/java.util.concurrent.CompletableFuture.reportGet(CompletableFuture.java:395)
	at java.base/java.util.concurrent.CompletableFuture.get(CompletableFuture.java:1999)
	at MqttCheck.main(MqttCheck.java:42)
Caused by: software.amazon.awssdk.crt.mqtt.MqttException: Old requests from the previous session are cancelled, and offline request will not be accept.

Potentially, similar issue:
aws/aws-iot-device-sdk-python#157

SDK version number
1.2.14 (latest released)

Platform/OS/Hardware/Device
What are you running the sdk on?

  • MS Windows 10 x64
  • Windows Subsystem for Linux 1 (Debian Buster x64)

To Reproduce (observed behavior)
Steps to reproduce the behavior (please share code)

Expected behavior

AwsIotMqttConnectionBuilder builder = AwsIotMqttConnectionBuilder
                .newMtlsBuilderFromPath("src/main/resources/device.crt",
                        "src/main/resources/device_priv.pem");

        ClientBootstrap clientBootstrap = new ClientBootstrap(null, null);

        MqttClientConnection clientConnection = builder
                .withBootstrap(clientBootstrap)
                .withClientId(clientId)
                .withCleanSession(true)
                .withPassword(keyPassword)
                .withCertificateAuthorityFromPath(null, "src/main/resources/AmazonRootCA1.pem")
                .withCertificateAuthorityFromPath(null, "src/main/resources/factory.crt")
                .withEndpoint(endpoint)
                .build();

        clientConnection.connect();
        System.out.println("Connected");

        CompletableFuture<Integer> future = clientConnection.publish(new MqttMessage("myTopic", "Hello World! from v2".getBytes()),
                QualityOfService.AT_LEAST_ONCE,
                false);

        System.out.println("Status of future=" + future.get());  // **exception thrown here**
        System.out.println("Message published");

        clientConnection.disconnect();
        System.out.println("Disconnected");

Logs/output

Exception in thread "main" 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.
	at java.base/java.util.concurrent.CompletableFuture.reportGet(CompletableFuture.java:395)
	at java.base/java.util.concurrent.CompletableFuture.get(CompletableFuture.java:1999)
	at MqttCheck.main(MqttCheck.java:42)
Caused by: software.amazon.awssdk.crt.mqtt.MqttException: Old requests from the previous session are cancelled, and offline request will not be accept.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugThis issue is a bug.closed-for-stalenessresponse-requestedWaiting on additional info and feedback. Will move to "closing-soon" in 2 days.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions