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

identifierRejected when connect to mosquitto 2.0 #325

Closed
duetocode opened this issue Sep 22, 2021 · 2 comments
Closed

identifierRejected when connect to mosquitto 2.0 #325

duetocode opened this issue Sep 22, 2021 · 2 comments

Comments

@duetocode
Copy link

Thanks for the great work.

The MqttServerClient works perfectly with the mosquitto broker 1.x until the broker is upgraded to 2.0.12.

Could someone please point me out if the MqttServerClient is compatible with the mosquitto V2 broker? Or do we need additional configuration?

The broker is a mosquitto 2.0.12 instance installed as a snap package on Debian 10 with the configuration below.

listener 2883 0.0.0.0
allow_anonymous true
persistence false

And the logs about the connection:

2021-09-22T07:45:51Z mosquitto.mosquitto[32470]: 1632296751: New client connected from xxx.xxx.xxx.xxxx:xxxxx as test-ABC (p2, c1, k0).
2021-09-22T07:45:51Z mosquitto.mosquitto[32470]: 1632296751: Bad socket read/write on client test-ABC: Invalid arguments provided.

The following is the log from flutter:

...  
flutter: 21-2021-09-22 15:45:51.553093 -- MqttClient::connect - keep alive is disabled  
flutter: 21-2021-09-22 15:45:51.553656 -- MqttConnectionHandlerBase::connect - server broker.xxx.xxx.xxx.com, port 2883  
flutter: 21-2021-09-22 15:45:51.553755 -- SynchronousMqttServerConnectionHandler::internalConnect entered  
flutter: 21-2021-09-22 15:45:51.553834 -- SynchronousMqttServerConnectionHandler::internalConnect - initiating connection try 0, auto reconnect in progress false  
flutter: 21-2021-09-22 15:45:51.553922 -- SynchronousMqttServerConnectionHandler::internalConnect - insecure TCP selected  
flutter: 21-2021-09-22 15:45:51.554015 -- SynchronousMqttServerConnectionHandler::internalConnect - calling connect  
flutter: 21-2021-09-22 15:45:51.554086 -- MqttNormalConnection::connect - entered  
flutter: 21-2021-09-22 15:45:51.636938 -- MqttServerConnection::_startListening  
flutter: 21-2021-09-22 15:45:51.637293 -- SynchronousMqttServerConnectionHandler::internalConnect - connection complete  
flutter: 21-2021-09-22 15:45:51.637337 -- SynchronousMqttServerConnectionHandler::internalConnect sending connect message  
flutter: 21-2021-09-22 15:45:51.637379 -- MqttConnectionHandlerBase::sendMessage - MQTTMessage of type MqttMessageType.connect  
Header: MessageType = MqttMessageType.connect, Duplicate = false, Retain = false, Qos = MqttQos.atMostOnce, Size = 0
Connect Variable Header: ProtocolName=MQTT, ProtocolVersion=4, ConnectFlags=Connect Flags: Reserved1=false, CleanStart=true, WillFlag=false, WillQos=MqttQos.atMostOnce, WillRetain=false, PasswordFlag=false, UserNameFlag=false, KeepAlive=0  
MqttConnectPayload - client identifier is : test-ABC  
flutter: 21-2021-09-22 15:45:51.638308 -- SynchronousMqttServerConnectionHandler::internalConnect - pre sleep, state = Connection status is connecting with return code of noneSpecified and a disconnection origin of none  
flutter: 21-2021-09-22 15:45:52.029188 -- MqttConnection::_onData  
flutter: 21-2021-09-22 15:45:52.031745 -- MqttServerConnection::_onData - message received MQTTMessage of type MqttMessageType.connectAck  
Header: MessageType = MqttMessageType.connectAck, Duplicate = false, Retain = false, Qos = MqttQos.atMostOnce, Size = 2  
Connect Variable Header: TopicNameCompressionResponse={0}, ReturnCode={MqttConnectReturnCode.identifierRejected}  
flutter: 21-2021-09-22 15:45:52.032841 -- MqttServerConnection::_onData - message available event fired  
flutter: 21-2021-09-22 15:45:52.034687 -- MqttConnectionHandlerBase::_connectAckProcessor  
flutter: 21-2021-09-22 15:45:52.036089 -- MqttConnectionHandlerBase::_connectAckProcessor connection rejected  
flutter: 21-2021-09-22 15:45:52.036624 -- MqttConnectionHandlerBase::_performConnectionDisconnect entered  
flutter: 21-2021-09-22 15:45:52.037142 -- MqttConnectionHandlerBase:: cancelling connect timer  
flutter: 21-2021-09-22 15:45:52.039630 -- MqttConnectionBase::_onDone - calling disconnected callback  
flutter: 21-2021-09-22 15:45:52.040428 -- SynchronousMqttServerConnectionHandler::internalConnect - post sleep, state = Connection status is disconnected with return code of identifierRejected and a disconnection origin of none
flutter: 21-2021-09-22 15:45:52.040900 -- SynchronousMqttServerConnectionHandler::internalConnect failed  
...

It seems that the connection message is rejected by the broker.

@shamblett
Copy link
Owner

The client has no knowledge of what broker its talking to, it only knows that protocol to use, from the log above -

flutter: 21-2021-09-22 15:45:52.036089 -- MqttConnectionHandlerBase::_connectAckProcessor connection rejected

Your broker is rejecting the connect message, the first thing to check is what version of MQTT you are setting the client to, you can use 3.1 or 3.1.1 using the setProtocol client methods, this must match your broker version. Some brokers are stricter than others with this. The second thing to check is if you are supplying your own connect message then take out things like will period settings etc. boil it down to the basics and see what happens.

Why brokers like mosquitto do not actually tell you what's wrong rather than just say 'Invalid arguments' baffles me slightly.

@duetocode
Copy link
Author

I managed to solve this by setting a non-zero value to the keepAlivePeriod property of the MqttServerClient isntance, after some trial and error. The problem may be related to this issue: eclipse/mosquitto#2309 .

Thanks!

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

2 participants