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

Source code thinking #685

Open
18716000127 opened this issue Sep 14, 2022 · 3 comments
Open

Source code thinking #685

18716000127 opened this issue Sep 14, 2022 · 3 comments

Comments

@18716000127
Copy link

18716000127 commented Sep 14, 2022

Minimal yet complete reproducer code (or URL to code) or complete log file

private void processConnectionLost(String clientID) { if (bindedSession.hasWill()) { postOffice.fireWill(bindedSession.getWill()); } if (bindedSession.isClean()) { LOG.debug("Remove session for client {}", clientID); sessionRegistry.remove(bindedSession.getClientID()); } else { bindedSession.disconnect(); } connected = false; //dispatch connection lost to intercept. String userName = NettyUtils.userName(channel); postOffice.dispatchConnectionLost(clientID,userName); LOG.trace("dispatch disconnection: userName={}", userName); }

`PostOffice.RouteResult processDisconnect(MqttMessage msg) {
final String clientID = NettyUtils.clientID(channel);
LOG.trace("Start DISCONNECT");
if (!connected) {
LOG.info("DISCONNECT received on already closed connection");
return PostOffice.RouteResult.success(clientID, CompletableFuture.completedFuture(null));
}

    return this.postOffice.routeCommand(clientID, "DISCONN", () -> {
        if (!isBoundToSession()) {
            LOG.debug("NOT processing disconnect {}, not bound.", clientID);
            return null;
        }
        bindedSession.disconnect();
        connected = false;
        channel.close().addListener(FIRE_EXCEPTION_ON_FAILURE);
        String userName = NettyUtils.userName(channel);
        postOffice.clientDisconnected(clientID, userName);
        LOG.trace("dispatch disconnection userName={}", userName);
        return null;
    });
}`

I don't understand the difference between them.And the MQTT Client normal disconnect,they will be executed.As a result, both notifyClientDisconnected() and notifyClientConnectionLost() will be executed.
Event
if (bindedSession.isClean()) { LOG.debug("Remove session for client {}", clientID); sessionRegistry.remove(bindedSession.getClientID()); } else { bindedSession.disconnect(); }
why is AND Logic?

Moquette MQTT version

branch:main

JVM version (e.g. java -version)

1.8

@18716000127
Copy link
Author

method processDisconnect()
not cotain channel.attr(NettyUtils.ATTR_KEY_CLIENTID).set(null) logic
so this method(NewNettyMQTTHandler.java->channelInactive()->handleConnectionLost()->processConnectionLost) will execute

@18716000127
Copy link
Author

processConnectionLost()
processDisconnect()
Why the two logics are inconsistent?

@18716000127
Copy link
Author

I think one behavior can only lead to one result, and multiple results do not conform to the rationality of the program design.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant