Navigation Menu

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

Exception raised when two MQTT client subscribes whith the same ClientID #44

Open
dtflx01 opened this issue Jun 13, 2017 · 5 comments
Open
Labels

Comments

@dtflx01
Copy link
Contributor

dtflx01 commented Jun 13, 2017

I found an Exception raised when two MQTT client subscribes whith the same ClientID.
The exception is raised in MqttPublisherManager.cs in method PublishThread() in the following line

var query = from p in this.retainedMessages where (new Regex(subscription.Topic)).IsMatch(p.Key)
// check for topics based also on wildcard with regex
select p.Value;
Exception is raised because subscription.Topic is null.
Each ClientID must be unique, but if it happens, this issue appears.

Regards

@VladimirAkopyan
Copy link
Member

What should the broker do instead thou? Drop connection? Refuse connection to the current one?

@dtflx01
Copy link
Contributor Author

dtflx01 commented Sep 19, 2017

Hi,
Yes I think that the Broker should refuse new connection.
Regards

@VladimirAkopyan
Copy link
Member

that does make sense

@VladimirAkopyan
Copy link
Member

Actually official spesification says that:

If validation is successful the Server performs the following steps.

If the ClientId represents a Client already connected to the Server then the Server MUST disconnect the existing Client [MQTT-3.1.4-2].
The Server MUST perform the processing of CleanSession that is described in section 3.1.2.4 [MQTT-3.1.4-3].
The Server MUST acknowledge the CONNECT Packet with a CONNACK Packet containing a zero return code [MQTT-3.1.4-4].
Start message delivery and keep alive monitoring

http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.html#_Toc398718032

Answer from stack-exchange: https://iot.stackexchange.com/questions/504/what-will-be-the-result-of-the-following-connection-scenario-in-an-mqtt-network

@nkostis
Copy link

nkostis commented Jan 3, 2018

As Vladimir says and as is common behaviour among brokers, the broker should allow the connection of the new client and disconnect the existing one, since they're considered the same client that tries to reconnect and the previous connection is "stale".
This may lead to attacks (if client id is known to others), but the other option would be to have stale connections remain stale forever (keep-alive can be disabled by a client).

so the question actually is: what does the broker currently do and how do you get into a situation where there are more than one clients with the same ID connected?
Because i use this broker as well and what i've seen it do is to indeed disconnect the original one.
And since my clients have an auto-reconnect mechanism, you actually see one client kick the other one out and vice versa for eternity

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

No branches or pull requests

3 participants