Skip to content

[Bug]: infinite reconnects on Android #1953

Open
@KirillRodichevUtorg

Description

@KirillRodichevUtorg

MQTTjs Version

5.10.1

Broker

nats

Environment

Browser

Description

On Android I end up with infinite reconnection attempts. On iOS it works fine.

Minimal Reproduction

My client setup

export const getMqttClient = ({
	clientId,
	username,
	password,
	...handlers
}: IMqttClientProps) => {
	const client = connect(MQTT_WS_URL, {
		clientId,
		username,
		password,
		resubscribe: true,
		manualConnect: true,
		reconnectPeriod: 5000,
		log: (...args) => {
			onLog?.(...args)
		},
	})

	client.on('message', (topic, message) => {
		handlers.onMessage(topic, message.toString())
	})

	client.on('connect', (packet) => {
		handlers.onConnect(packet)
	})

	client.on('packetsend', (packet) => {
		handlers.onPacketSend.(packet)
	})

	client.on('reconnect', () => {
		handlers.onReconnect.()
	})

	client.on('disconnect', (packet) => {
		handlers.onDisconnect.(packet)
	})

	client.on('error', (error) => {
		handlers.onError.(error)
	})

	client.on('offline', () => {
		handlers.onOffline.()
	})

	return client
}

Debug logs

"MqttClient :: version:", "5.10.1"
"MqttClient :: environment", "browser"
"MqttClient :: options.protocol", "wss"
"MqttClient :: options.protocolVersion", 4
"MqttClient :: options.username", "01JCGF9MJ7T6ZGGYHYVJ8W25GW"
"MqttClient :: options.keepalive", 60
"MqttClient :: options.reconnectPeriod", 5000
"MqttClient :: options.rejectUnauthorized", null
"MqttClient :: options.properties.topicAliasMaximum", null
"MqttClient :: clientId", "01JCGF9MJ7T6ZGGYHYVJ8W25GW_28fd2acd1dcdcebb"
"connect :: calling method to clear reconnect"
"_clearReconnect : clearing reconnect timer"
"connect :: using streamBuilder provided to client to create stream"
"connect :: pipe stream to writable stream"
"connect: sending packet 'connect'"
"_writePacket :: packet: %O",
{"cmd":"connect","protocolId":"MQTT","protocolVersion":4,"clean":true,"clientId":"01JCGF9MJ7T6ZGGYHYVJ8W25GW_28fd2acd1dcdcebb","keepalive":60,"username":"01JCGF9MJ7T6ZGGYHYVJ8W25GW","password":"eyJOeXAIOIJKV1QiLCJhbGciOiJIZDIIN..."}
"_writePacket :: emitting 'packetsend'"
"2024-11-12T15:19:00.590Z - CONNECT"
"_writePacket :: writing to stream"
"_writePacket :: writeToStream result", true
"subscribe: array topic", "transactions-history/message/transaction/completed/01JCGF9MJ7T6ZGGYHYVJ8W25GW"
"subscribe: pushing topic '%s' and qos '%s' to subs list", "transactions-history/message/transaction/completed/01JCGF9MJ7T6ZGGYHYVJ8W25GW", 1
"subscribe :: resubscribe true"
"subscribe :: call _sendPacket"
"_sendPacket :: (%s) :: start", "01JCGF9MJ7T6ZGGYHYVJ8W25GW_28fd2acd1dcdcebb"
"_sendPacket :: client not connected. Storing packet offline."
"_storePacket :: packet: %o",
{
  "cmd":"subscribe",
  "subscriptions":[
    {"topic":"transactions-history/message/transaction/completed/01JCGF9MJ7T6ZGGYHYVJ8W25GW", "qos":1}
  ],
  "messageId":43303
}
"_storePacket :: cb? %s", true
"writable stream :: parsing buffer"
"writable stream :: parsing buffer"
"parser :: on packet push to packets array."
"work :: getting next packet in queue"
"work :: packet pulled from queue"
"_handlePacket :: emitting packetreceive"
"_handleConnack"
"_setupKeepaliveManager :: keepalive %d (seconds)",60
"KeepaliveManager: set keepalive to 60000ms"
"connect :: sending queued packets"
"deliver :: entry %o",null
"_resubscribe"
CONNECT
"writable stream :: parsing buffer"
"parser :: on packet push to packets array."
"work :: getting next packet in queue"
"work :: packet pulled from queue"
"_handlePacket :: emitting packetreceive"
"_handleConnack"
"_setupKeepaliveManager :: keepalive %d (seconds)",60
"KeepaliveManager: set keepalive to 60000ms"
"connect :: sending queued packets"
"deliver :: entry %o",{"packet":{"cmd":"subscribe","subscriptions":[{"topic":"transactions-history/message/transaction/completed/01JCGF9MJ7T6ZGGYHYVJ8W25GW","qos":1}],"messageId":43303}}
"deliver :: call _sendPacket for %o"
"_sendPacket :: (%s) :: start","01JCGF9MJ7T6ZGGYHYVJ8W25GW_28fd2acd1dcdcebb"
"_writePacket :: packet: %O",{"cmd":"subscribe","subscriptions":[{"topic":"transactions-history/message/transaction/completed/01JCGF9MJ7T6ZGGYHYVJ8W25GW","qos":1}],"messageId":43303}
"_writePacket :: emitting 'packetsend'"
2024-11-12T15:19:01.321Z - SUBSCRIBE
"_writePacket :: writing to stream"
"_writePacket :: writeToStream result %s",true
"_writePacket :: invoking cb"
"noop ::",null
"deliver :: entry %o",null
"_resubscribe"
CONNECT
"(%s)stream :: on close","01JCGF9MJ7T6ZGGYHYVJ8W25GW_28fd2acd1dcdcebb"
"_flushVolatile :: deleting volatile messages from the queue and setting their callbacks as error function"
"stream: emit close to MqttClient"
"close :: connected set to 'false'"
"close :: clearing connackTimer"
"_destroyKeepaliveManager :: destroying keepalive manager"
"close :: calling _setupReconnect"
"_setupReconnect :: emit 'offline' state"
OFFLINE
"_setupReconnect :: set 'reconnecting' to 'true'"
"_setupReconnect :: setting reconnectTimer for %d ms",5000
"writable stream :: parsing buffer"
"parser :: on packet push to packets array."
"work :: getting next packet in queue"
"work :: packet pulled from queue"
"_handlePacket :: emitting packetreceive"
"_reschedulePing :: rescheduling ping"
"_handleAck :: packet type","suback"
"reconnectTimer :: reconnect triggered!"
"_reconnect: emitting reconnect to client"
RECONNECT
"_reconnect: calling connect"
"connect :: calling method to clear reconnect"
"_clearReconnect : clearing reconnect timer"
"connect :: using streamBuilder provided to client to create stream"
"connect :: pipe stream to writable stream"
"connect: sending packet 'connect'"
"_writePacket :: packet: %O",{"cmd":"connect","protocolId":"MQTT","protocolVersion":4,"clean":true,"clientId":"01JCGF9MJ7T6ZGGYHYVJ8W25GW_28fd2acd1dcdcebb","keepalive":60,"username":"01JCGF9MJ7T6ZGGYHYVJ8W25GW","password":"eyJOeXAIOIJKV1QiLCJhbGciOiJIZDIIN..."}
"_writePacket :: emitting 'packetsend'"
2024-11-12T15:19:06.797Z - CONNECT
"_writePacket :: writing to stream"
"_writePacket :: writeToStream result %s",true
"writable stream :: parsing buffer"
"parser :: on packet push to packets array."
"work :: getting next packet in queue"
"work :: packet pulled from queue"
"_handlePacket :: emitting packetreceive"
"_handleConnack"
"_setupKeepaliveManager :: keepalive %d (seconds)",60
"KeepaliveManager: set keepalive to 60000ms"
"connect :: sending queued packets"
"deliver :: entry %o",null
"_resubscribe"

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions