Not authorized Error on connection


We are using pay as you go for mqtt.
from today morning we started getting
org.eclipse.paho.mqttv5.common.MqttException: Not authorized
error on connection.

Credentials are same & correct from long time they are not updated.

Please help with this.

Hi @vijaysy,

Can you please share your cluster address as well as the clientID of the client that is getting the NOT_AUTHORIZED error?

Thank you,

Hi @fraschbi

Address :

I don’t have client id since we generate it dynamically.

Hi @vijaysy

Thanks for sharing the cluster url.
Most likely when the password is incorrect then you will receive a “Not authorized” error on connection.

We are checking further, meantime can please try to change the password and do a quick test by using mqtt cli client as mentioned in the startup guide of MQTT CLI client. Please let us know if you still get the same error.

Kind regards,

Hi @SShet

It got fixed after created new user name and password.
also again we faced same issue on another cluster/broker.

Looks like it is recurring, can you pls look into it again

@vijaysy, can you rule out copy/paste errors or typos in the password field?
So far all our tests have been successful.

Hi @zingiber

Yes, I double checked for errors and typos.

Can it be because of 2 or more clients getting connected with same client ID?
Since after restarting process I am not seeing this issue.

Also can we check broker side logs for URL?

Hey vijaysy,

A second connection using the same clientId as that of a currently connected session will always lead to the broker closing the connection to the prior client. This mechanism is called client take-over and is mandated by the MQTT specification.

The “Not authorized” would make it seem like the new connection attempt was failing. Was this the case, or were already connected sessions losing their connections? Can you please share a clientId of affected clients?

Kind regards,

Hi @zingiber

About Second connection explanation → I got it.

I am getting this exception from this line of client at 6f35dcb785597a6fd49091efe2dba47513939420 · eclipse/ · GitHub

I went through the client code.

We are getting this error message POST establishing the connection, while sending/pushing the message.

Unfortunately, I did not add logs for client ids. I don’t have em.

Is it possible to check broker logs, from broker URL details at your end?

Strange part is, restart of the application is fixing this issue.

Hi @vijaysy,

Have you tried running your code against a locally hosted HiveMQ broker?
From what you are describing my best guess would be that the client is not re-using the authentication credentials on automatic re-connect.
Could that be possible?


Hi @fraschbi

Yes, that could be an issue.
I am deploying changes to capture clientId and user name & password
used while reconnecting.

Also will try to-reproduce with local broker.

Hi All

There was a bug in code, in re-connect the password was not being set.
Thank you for the help & really sorry for inconvenience.

Thank you