Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change isConnected flag only in handleClose #113

Closed
wants to merge 1 commit into from

Conversation

Sammers21
Copy link
Contributor

Partly solves #109

@Sammers21
Copy link
Contributor Author

@vietj , @ppatierno , can you review, please?

@ffeii
Copy link

ffeii commented Nov 15, 2018

@Sammers21 , the isConnected field will never be true.

@vietj
Copy link
Contributor

vietj commented Nov 15, 2018

I think we need to have a test for the issue you are trying to fix

Copy link
Member

@ppatierno ppatierno left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Sammers21 with this change, the client is going to close the TCP connection if it gets a negative CONNACK from the server, right? Why it should do that? On the same TCP connection the client could be able to send a new CONNECT packet to be successful (maybe the problem is about authentication with username and password). Tbh I don't remember why the close handler was tight to the isConnected flag so that we can just remove the check on isConnected in the handleClosed.

@Sammers21
Copy link
Contributor Author

On the same TCP connection the client could be able to send a new CONNECT packet to be successful (maybe the problem is about authentication with username and password)

Yes, but the current API does not allow as to do this, I mean sending COONECT twice on the same connection.

Tbh I don't remember why the close handler was tight to the isConnected flag so that we can just remove the check on isConnected in the handleClosed.

I think we need to clearly define what isConnected and handleClose means. Either they are related to a connection on the TCP level or MQTT session.

@SunFeiyue
Copy link

Tbh I don't remember why the close handler was tight to the isConnected flag so that we can just remove the check on isConnected in the handleClosed.

@ppatierno @Sammers21 Or, is it possible to add a new flag to indicate the TCP connection is connected?

@vietj
Copy link
Contributor

vietj commented Nov 16, 2018

I think having first a test that reproduce the issue would be good, so we can then settle or not on the usefulness of the PR.

@ppatierno
Copy link
Member

I agree with Julien, we first need a test for reproducing it and then we can think about the better solution.

@ffeii
Copy link

ffeii commented Nov 16, 2018

public class ConnectHandlerNotCalled extends io.vertx.core.AbstractVerticle {

    public static void main(String... args) {
        io.vertx.core.Vertx.vertx().deployVerticle(ConnectHandlerNotCalled.class.getName());
    }

    @Override
    public void start() throws Exception {

        io.vertx.mqtt.MqttServer.create(vertx).endpointHandler(endpoint -> {
            System.out.println("CONNECT from " + endpoint.clientIdentifier());
            // Do not send CONNACK
            // endpoint.accept(false);
        }).listen(1883, lh -> {
            System.out.println("Server is listening");
            io.vertx.mqtt.MqttClient.create(vertx).connect(1883, "127.0.0.1", ch -> System.out.println("ConnectHandler called"));
        });
    }
}

@Sammers21 Sammers21 force-pushed the closing_connection_properly branch from 6b1f5bf to 8c7e60a Compare December 3, 2018 07:01
@Sammers21
Copy link
Contributor Author

Just added a test case. If we don't receive a CONNACK packet within a period of time, we will treat it as an unsuccessful attempt to establish a MQTT session

@Sammers21 Sammers21 force-pushed the closing_connection_properly branch from 8c7e60a to 820c610 Compare December 3, 2018 07:08
Copy link
Contributor

@konradmichael konradmichael left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also recommend to change the title, if possible.
The isConnected variable is still changed in the conAck-handler

Async async = context.async(1);
MqttServer mqttServer = MqttServer.create(vertx);
mqttServer.endpointHandler(mqttEndpoint -> {
vertx.setTimer(serverResponseInSeconds * 1000, action -> mqttEndpoint.close());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not see a reason to set a timer that closes the endpoint.
It is sufficient to do nothing to make the test pass.

Keeping this action could lead to the conclusion that your waiting for the TCP-Connection to be closed, which is not what is intended

@Sammers21 Sammers21 closed this Oct 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

6 participants