Skip to content

MQTT client connection close while publish "+" #258

Description

Version

5.0.4

Context

While publishing a message with invalid Topic contains "+":

Client immediately closes TCP connection (TCP FIN/ACK)

I would expect an info that + is not allowed to sent as topic, but the connection close is quite hard to find the problem. I faced into that issue with copied example code (which responses to subscription topics):
endpoint.publish(subscribe.topicSubscriptions().get(0).topicName(),
Steps to reproduce

Reproduceable with Version 4 and also newest 5.0.4 version at a simple unit test:

While publishing: "test/+": it will fail, if publishing: "test/1" -> connection stay alive

@test
@timeout(value = 10, timeUnit = TimeUnit.SECONDS)
void testMethodMessage(Vertx vertx, VertxTestContext testContext) throws Throwable {
MqttServer server = MqttServer.create(vertx);

server.endpointHandler(endpoint -> {
endpoint.accept(false);

endpoint.subscribeHandler(subscribe -> {
  endpoint.subscribeAcknowledge(subscribe.messageId(), List.of(MqttQoS.EXACTLY_ONCE));

});
vertx.setTimer(1000, id -> {

  endpoint.publish("test/+", // "test/1",
    Buffer.buffer("Hello from the Vert.x MQTT server"),
    MqttQoS.EXACTLY_ONCE,
    false,
    false);
});

// specifing handlers for handling QoS 1 and 2
endpoint.publishAcknowledgeHandler(messageId -> {

  System.out.println("Received ack for message = " + messageId);

}).publishReceivedHandler(messageId -> {

  endpoint.publishRelease(messageId);

}).publishCompletionHandler(messageId -> {

  System.out.println("Received ack for message = " + messageId);
});
//testContext.completeNow();

})
.listen(1883, "0.0.0.0").onComplete(ar -> {
if (ar.succeeded()) {

  MqttClient client = MqttClient.create(vertx);
  client.publishHandler(msg -> {

    testContext.completeNow();
  });
  client.closeHandler(v -> {
    System.out.println("MQTT connection to broker closed!");
  });


  client.connect(1883, "127.0.0.1").onComplete(ar2 -> {
    if (ar2.succeeded()) {

      client.subscribe("test/+", MqttQoS.EXACTLY_ONCE.value());
    } else {
      testContext.failNow(ar.cause());
    }
  });

} else {
  testContext.failNow(ar.cause());
}

});

}

Steps to reproduce

  1. use UnitTest code above and execute it -> test should fail as long bug is part of mqtt-client version

Do you have a reproducer?

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions