Search code examples
google-cloud-platformmqttgoogle-cloud-iot

Many "MQTT disconnect - ALREADY_EXISTS" error in Google Cloud IoT console log


I use Google IoT Core in my project as MQTT broker to connect IoT embedded devices based on Atmel MCU to Goole Cloud Plattform.

In the plattform log, i experience many "MQTT DISCONNECT" errors.

jsonPayload: {
  disconnectType: "SERVER"   
  eventType: "DISCONNECT"   
  protocol: "MQTT"   
  resourceName: "projects/xxxxxxx/locations/europe-west1/registries/xxxxxxxx/devices/1234567890"   
  serviceName: "cloudiot.googleapis.com"   
  status: {
   code: 6    
   description: "ALREADY_EXISTS"    
   message: "SERVER: The connection was closed because there is another active connection with the same device ID."    
  }
 }
labels: {
  device_id: "d1234567890"   
 }
 logName: "projects/xxxxxxxxx/logs/cloudiot.googleapis.com%2Fdevice_activity" 

The error is generated when the device boots-up and connect to MQTT server. Despite this error, the connection is successful, as is the subscription to topics and message publishing.

I understand that the previous connection was not closed gracefully, but it is imbossible by the nature of the embedded device, that is meant to be always connected, and eventually turned off by disconnecting power supply (so it cannot send a disconnect message to server before).

The device ID is always the same at every reconnection, but unique per-device; i use chip serial number as in some Google's examples.

My question is, if there is a solution to this error, that can be ignored in developement phase, but would be unwanted behavior in the production environment.


Solution

  • The MQTT connection to the device bridge has a few special properties that can cause disconnects. For device connections, you are limited to one connection per-device (or device ID, for the sakes of a gateway). It looks to me like you're trying to connect the same device twice and it's causing a disconnect.

    It's possible that you have a client that tries to open up two connections, or you are connecting a second client. If you're connecting the same device twice, the device will be disconnected. Maybe your client is setup to open up multiple channels or your application logic is reconnecting without disconnecting.

    There are various other reasons for disconnects, for example, if you try to publish with the incorrect QoS or to an invalid topic but this doesn't appear to be that given publish is working on subsequent connections.