shamblett / mqtt_client

A server and browser based MQTT client for dart
Other
548 stars 176 forks source link

error:Bad state: Cannot add new events after calling close #536

Closed BIG-BEARC closed 1 month ago

BIG-BEARC commented 4 months ago

I only disconnect and then reconnect upon receiving the exception SocketException: Software caused connection abort. MqttClient

   _mqttClient = MqttServerClient.withPort(server, clientIdentifier, port)
      ..logging(on: !BaseUrlManager().isPRO())
      ..setProtocolV311()
      ..keepAlivePeriod = 20 
      ..onConnected = _onConnected 
      ..onDisconnected = _onDisconnected
      ..onSubscribed = _onSubscribed
      ..onSubscribeFail = _onSubscribeFail
      ..onUnsubscribed = _onUnSubscribed
      ..autoReconnect = true 
      ..onAutoReconnect = _onAutoReconnect
      ..onAutoReconnected = _onAutoReconnected
      ..resubscribeOnAutoReconnect = true
      // ..connectTimeoutPeriod = 10000 
      ..pongCallback = _pong; 
    _mqttClient?.connectionMessage = connMess;

  disconnect() {
    if (_mqttClient?.connectionStatus?.state == MqttConnectionState.connected || _mqttClient?.connectionStatus?.state == MqttConnectionState.connecting) {
      _mqttClient?.disconnect();
    }
  }

Stack trace

_BroadcastStreamController.add (dart:async/broadcast_stream_controller.dart:243) 
EventBus.fire (package:event_bus/event_bus.dart:61)   
MqttConnectionHandlerBase.autoReconnect (package:mqtt_client/src/connectionhandling/mqtt_client_mqtt_connection_handler_base.dart:153)
<asynchronous suspension>

mqtt_client: 10.0.0

Did I make a mistake somewhere?

shamblett commented 4 months ago

I need more of the log, please supply a full client log from when you first connect.

BIG-BEARC commented 3 months ago

I need more of the log, please supply a full client log from when you first connect.

Thank you for your reply,here is the log:

I/flutter ( 3721): ┌───────────────────────────────────────────────────────
I/flutter ( 3721): │ #0   LoggerUtils.e (package:cashier/utils/logger.dart:71:12)
I/flutter ( 3721): │ #1   MqttManager._log (package:cashier/net/mqtt/mqtt_manager.dart:320:26)
I/flutter ( 3721): │ ⛔ MQTT-->MqttManager init,server:mqtt-xxxxx
I/flutter ( 3721): │ ⛔  port:1883
I/flutter ( 3721): │ ⛔  clientIdentifier:GID_iot_print@@@xxxxx
I/flutter ( 3721): │ ⛔  username:Signature|LTAI5tNFz4kpxiL181xKiPkk|xxxxx
I/flutter ( 3721): │ ⛔  password:dS/OU2BguO/hM8PmqodIllFjMxY=
I/flutter ( 3721): └───────────────────────────────────────────────────────

I/flutter ( 3721): ┌───────────────────────────────────────────────────────
I/flutter ( 3721): │ #0   LoggerUtils.e (package:cashier/utils/logger.dart:71:12)
I/flutter ( 3721): │ #1   MqttManager._log (package:cashier/net/mqtt/mqtt_manager.dart:320:26)
I/flutter ( 3721): ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
I/flutter ( 3721): │ ⛔ MQTT-->_start connect()
I/flutter ( 3721): └───────────────────────────────────────────────────────
I/flutter ( 3721): ┌───────────────────────────────────────────────────────
I/flutter ( 3721): │ #0   LoggerUtils.e (package:cashier/utils/logger.dart:71:12)
I/flutter ( 3721): │ #1   MqttManager._log (package:cashier/net/mqtt/mqtt_manager.dart:320:26)
I/flutter ( 3721): ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
I/flutter ( 3721): │ ⛔ MQTT-->connect
I/flutter ( 3721): └───────────────────────────────────────────────────────
I/flutter ( 3721): 1-2024-05-28 17:00:12.399985 -- MqttClient::connect - Connection timeout period is 5000 milliseconds
I/flutter ( 3721): 1-2024-05-28 17:00:12.422882 -- MqttClient::connect - keep alive is enabled with a value of 20 seconds
I/flutter ( 3721): 1-2024-05-28 17:00:12.436311 -- MqttConnectionKeepAlive:: Initialised with a keep alive value of 20 seconds
I/flutter ( 3721): 1-2024-05-28 17:00:12.436877 -- MqttConnectionKeepAlive:: Disconnect on no ping response is disabled
I/flutter ( 3721): 1-2024-05-28 17:00:12.448820 -- MqttConnectionHandlerBase::connect - server mqtt-cn-20p34ha2601.mqtt.aliyuncs.com, port 1883
I/flutter ( 3721): 1-2024-05-28 17:00:12.457129 -- SynchronousMqttServerConnectionHandler::internalConnect entered
I/flutter ( 3721): 1-2024-05-28 17:00:12.458126 -- SynchronousMqttServerConnectionHandler::internalConnect - initiating connection try 0, auto reconnect in progress false
I/flutter ( 3721): 1-2024-05-28 17:00:12.460153 -- SynchronousMqttServerConnectionHandler::internalConnect - insecure TCP selected
I/flutter ( 3721): 1-2024-05-28 17:00:12.464312 -- SynchronousMqttServerConnectionHandler::internalConnect - calling connect
I/flutter ( 3721): 1-2024-05-28 17:00:12.466892 -- MqttNormalConnection::connect - entered

I/flutter ( 3721): 1-2024-05-28 17:00:12.980714 -- MqttServerConnection::_startListening
I/flutter ( 3721): 1-2024-05-28 17:00:12.984777 -- SynchronousMqttServerConnectionHandler::internalConnect - connection complete
I/flutter ( 3721): 1-2024-05-28 17:00:12.985260 -- SynchronousMqttServerConnectionHandler::internalConnect sending connect message
I/flutter ( 3721): 1-2024-05-28 17:00:12.987158 -- MqttConnectionHandlerBase::sendMessage - MQTTMessage of type MqttMessageType.connect
I/flutter ( 3721): Header: MessageType = MqttMessageType.connect, Duplicate = false, Retain = false, Qos = MqttQos.atMostOnce, Size = 0
I/flutter ( 3721): Connect Variable Header: ProtocolName=MQTT, ProtocolVersion=4, ConnectFlags=Connect Flags: Reserved1=false, CleanStart=false, WillFlag=false, WillQos=MqttQos.atMostOnce, WillRetain=false, PasswordFlag=true, UserNameFlag=true, KeepAlive=20
I/flutter ( 3721): MqttConnectPayload - client identifier is : GID_iot_print@@@301105506486579998720015
I/flutter ( 3721): 1-2024-05-28 17:00:13.049933 -- SynchronousMqttServerConnectionHandler::internalConnect - pre sleep, state = Connection status is connecting with return code of noneSpecified and a disconnection origin of none

I/flutter ( 3721): 1-2024-05-28 17:00:13.151651 -- MqttConnection::onData
I/flutter ( 3721): 1-2024-05-28 17:00:13.180629 -- MqttServerConnection::_onData - message received MQTTMessage of type MqttMessageType.connectAck
I/flutter ( 3721): Header: MessageType = MqttMessageType.connectAck, Duplicate = false, Retain = false, Qos = MqttQos.atMostOnce, Size = 2
I/flutter ( 3721): Connect Variable Header: TopicNameCompressionResponse={0}, ReturnCode={MqttConnectReturnCode.connectionAccepted}
I/flutter ( 3721): 1-2024-05-28 17:00:13.184457 -- MqttServerConnection::_onData - message available event fired
I/flutter ( 3721): 1-2024-05-28 17:00:13.189336 -- MqttConnectionHandlerBase::_connectAckProcessor
I/flutter ( 3721): 1-2024-05-28 17:00:13.190854 -- MqttConnectionHandlerBase:_connectAckProcessor - state = connected

I/flutter ( 3721): │ ⛔ MQTT-->onConnected

I/flutter ( 3721): │ #0   LoggerUtils.d (package:cashier/utils/logger.dart:47:12)
I/flutter ( 3721): │ #1   MqttManager.updateMqttConnectState (package:cashier/net/mqtt/mqtt_manager.dart:211:26)

I/flutter ( 3721): │ 🐛 mqttConnectState:MqttConnectChangeEvent{isConnect: true, mqttConnectState: connected}

I/flutter ( 3721): │ 🐛 mqttConnectState state:MqttConnectionState.connected

I/flutter ( 3721): 1-2024-05-28 17:00:13.227719 -- MqttConnectionHandlerBase:: cancelling connect timer

I/flutter ( 3721): 1-2024-05-28 17:00:13.243132 -- SynchronousMqttServerConnectionHandler::internalConnect - post sleep, state = Connection status is connected with return code of connectionAccepted and a disconnection origin of none
I/flutter ( 3721): 1-2024-05-28 17:00:13.244228 -- SynchronousMqttServerConnectionHandler::internalConnect exited with state Connection status is connected with return code of connectionAccepted and a disconnection origin of none

I/flutter ( 3721): │ ⛔ MQTT-->mqttClientConnectionStatus?.returnCode == MqttConnectReturnCode.connectionAccepted

I/flutter ( 3721): │ ⛔ MQTT-->_mqttClient?.updates!

I/flutter ( 3721): 1-2024-05-28 17:00:13.319343 -- MqttConnectionHandlerBase::sendMessage - MQTTMessage of type MqttMessageType.subscribe
I/flutter ( 3721): Header: MessageType = MqttMessageType.subscribe, Duplicate = false, Retain = false, Qos = MqttQos.atLeastOnce, Size = 0
I/flutter ( 3721): Subscribe Variable Header: MessageIdentifier={1}
I/flutter ( 3721): Payload: Subscription [{1}]
I/flutter ( 3721): {{ Topic={iot/print/301105506486579998720015}, Qos={MqttQos.atLeastOnce} }}

I/flutter ( 3721): 1-2024-05-28 17:00:13.330197 -- MqttConnectionHandlerBase::sendMessage - MQTTMessage of type MqttMessageType.subscribe
I/flutter ( 3721): Header: MessageType = MqttMessageType.subscribe, Duplicate = false, Retain = false, Qos = MqttQos.atLeastOnce, Size = 0
I/flutter ( 3721): Subscribe Variable Header: MessageIdentifier={2}
I/flutter ( 3721): Payload: Subscription [{1}]
I/flutter ( 3721): {{ Topic={iot/order/301105506486579998720015}, Qos={MqttQos.atMostOnce} }}

I/flutter ( 3721): 1-2024-05-28 17:00:13.334419 -- MqttConnectionHandlerBase::sendMessage - MQTTMessage of type MqttMessageType.subscribe
I/flutter ( 3721): Header: MessageType = MqttMessageType.subscribe, Duplicate = false, Retain = false, Qos = MqttQos.atLeastOnce, Size = 0
I/flutter ( 3721): Subscribe Variable Header: MessageIdentifier={3}
I/flutter ( 3721): Payload: Subscription [{1}]
I/flutter ( 3721): {{ Topic={iot/goods/301105506486579998720015}, Qos={MqttQos.atMostOnce} }}

I/flutter ( 3721): 1-2024-05-28 17:00:13.338451 -- MqttConnectionHandlerBase::sendMessage - MQTTMessage of type MqttMessageType.subscribe
I/flutter ( 3721): Header: MessageType = MqttMessageType.subscribe, Duplicate = false, Retain = false, Qos = MqttQos.atLeastOnce, Size = 0
I/flutter ( 3721): Subscribe Variable Header: MessageIdentifier={4}
I/flutter ( 3721): Payload: Subscription [{1}]
I/flutter ( 3721): {{ Topic={iot/takeout/301105506486579998720015}, Qos={MqttQos.atLeastOnce} }}

I/flutter ( 3721): 1-2024-05-28 17:00:13.343015 -- MqttConnectionHandlerBase::sendMessage - MQTTMessage of type MqttMessageType.subscribe
I/flutter ( 3721): Header: MessageType = MqttMessageType.subscribe, Duplicate = false, Retain = false, Qos = MqttQos.atLeastOnce, Size = 0
I/flutter ( 3721): Subscribe Variable Header: MessageIdentifier={5}
I/flutter ( 3721): Payload: Subscription [{1}]
I/flutter ( 3721): {{ Topic={iot/callNumber/301105506486579998720015}, Qos={MqttQos.atMostOnce} }}
I/flutter ( 3721): 1-2024-05-28 17:00:13.346437 -- MqttConnectionHandlerBase::sendMessage - MQTTMessage of type MqttMessageType.subscribe
I/flutter ( 3721): Header: MessageType = MqttMessageType.subscribe, Duplicate = false, Retain = false, Qos = MqttQos.atLeastOnce, Size = 0
I/flutter ( 3721): Subscribe Variable Header: MessageIdentifier={6}
I/flutter ( 3721): Payload: Subscription [{1}]
I/flutter ( 3721): {{ Topic={iot/version}, Qos={MqttQos.atMostOnce} }}

I/flutter ( 3721): 1-2024-05-28 17:00:13.349894 -- MqttConnectionHandlerBase::sendMessage - MQTTMessage of type MqttMessageType.subscribe
I/flutter ( 3721): Header: MessageType = MqttMessageType.subscribe, Duplicate = false, Retain = false, Qos = MqttQos.atLeastOnce, Size = 0
I/flutter ( 3721): Subscribe Variable Header: MessageIdentifier={7}
I/flutter ( 3721): Payload: Subscription [{1}]
I/flutter ( 3721): {{ Topic={iot/version/2}, Qos={MqttQos.atMostOnce} }}

I/flutter ( 3721): │ #0   LoggerUtils.e (package:cashier/utils/logger.dart:71:12)
I/flutter ( 3721): │ #1   CommonLogic.changeMqttState (package:cashier/pub/get_logic/common_logic.dart:381:26)
I/flutter ( 3721): │ ⛔ changeMqttState MqttConnectChangeEvent{isConnect: true, mqttConnectState: connected}

I/flutter ( 3721): 1-2024-05-28 17:00:13.883846 -- MqttConnection::onData
I/flutter ( 3721): 1-2024-05-28 17:00:13.897116 -- MqttServerConnection::_onData - message received MQTTMessage of type MqttMessageType.subscribeAck
I/flutter ( 3721): Header: MessageType = MqttMessageType.subscribeAck, Duplicate = false, Retain = false, Qos = MqttQos.atMostOnce, Size = 3
I/flutter ( 3721): SubscribeAck Variable Header: MessageIdentifier={1}
I/flutter ( 3721): Payload: Qos grants [{1}]
I/flutter ( 3721): {{ Grant={MqttQos.atLeastOnce} }}
I/flutter ( 3721): 
I/flutter ( 3721): 1-2024-05-28 17:00:13.902138 -- MqttServerConnection::_onData - message available event fired
I/flutter ( 3721): 1-2024-05-28 17:00:13.902924 -- MqttServerConnection::_onData - message received MQTTMessage of type MqttMessageType.subscribeAck
I/flutter ( 3721): Header: MessageType = MqttMessageType.subscribeAck, Duplicate = false, Retain = false, Qos = MqttQos.atMostOnce, Size = 3
I/flutter ( 3721): SubscribeAck Variable Header: MessageIdentifier={7}
I/flutter ( 3721): Payload: Qos grants [{1}]
I/flutter ( 3721): {{ Grant={MqttQos.atMostOnce} }}
I/flutter ( 3721): 
I/flutter ( 3721): 1-2024-05-28 17:00:13.903621 -- MqttServerConnection::_onData - message available event fired
I/flutter ( 3721): 1-2024-05-28 17:00:13.907565 -- MqttConnectionHandlerBase::messageAvailable - message type is MqttMessageType.subscribeAck

I/flutter ( 3721): │ ⛔ MQTT-->_onSubscribed topic:iot/print/301105506486579998720015

I/flutter ( 3721): common_utils e  _getDeviceId spDeviceId ===Android_4401000606_LANDI_237ACCH00010  shopId:4401000606 deviceIdMatchShopId:true
I/flutter ( 3721): common_utils e  _getDeviceId deviceId ===Android_4401000606_LANDI_237ACCH00010
I/flutter ( 3721): 1-2024-05-28 17:00:13.922531 -- MqttConnectionHandlerBase::messageAvailable - message type is MqttMessageType.subscribeAck

I/flutter ( 3721): │ ⛔ MQTT-->_onSubscribed topic:iot/version/2

I/flutter ( 3721): 1-2024-05-28 17:00:14.474251 -- MqttConnection::onData
I/flutter ( 3721): 1-2024-05-28 17:00:14.475136 -- MqttServerConnection::_onData - message received MQTTMessage of type MqttMessageType.subscribeAck
I/flutter ( 3721): Header: MessageType = MqttMessageType.subscribeAck, Duplicate = false, Retain = false, Qos = MqttQos.atMostOnce, Size = 3
I/flutter ( 3721): SubscribeAck Variable Header: MessageIdentifier={2}
I/flutter ( 3721): Payload: Qos grants [{1}]
I/flutter ( 3721): {{ Grant={MqttQos.atMostOnce} }}
I/flutter ( 3721): 
I/flutter ( 3721): 1-2024-05-28 17:00:14.476542 -- MqttServerConnection::_onData - message available event fired
I/flutter ( 3721): 1-2024-05-28 17:00:14.477533 -- MqttServerConnection::_onData - message received MQTTMessage of type MqttMessageType.subscribeAck
I/flutter ( 3721): Header: MessageType = MqttMessageType.subscribeAck, Duplicate = false, Retain = false, Qos = MqttQos.atMostOnce, Size = 3
I/flutter ( 3721): SubscribeAck Variable Header: MessageIdentifier={3}
I/flutter ( 3721): Payload: Qos grants [{1}]
I/flutter ( 3721): {{ Grant={MqttQos.atMostOnce} }}
I/flutter ( 3721): 
I/flutter ( 3721): 1-2024-05-28 17:00:14.478427 -- MqttServerConnection::_onData - message available event fired
I/flutter ( 3721): 1-2024-05-28 17:00:14.479479 -- MqttConnectionHandlerBase::messageAvailable - message type is MqttMessageType.subscribeAck

I/flutter ( 3721): │ ⛔ MQTT-->_onSubscribed topic:iot/order/301105506486579998720015

I/flutter ( 3721): 1-2024-05-28 17:00:14.502862 -- MqttConnectionHandlerBase::messageAvailable - message type is MqttMessageType.subscribeAck

I/flutter ( 3721): │ #0   LoggerUtils.e (package:cashier/utils/logger.dart:71:12)
I/flutter ( 3721): │ #1   MqttManager._log (package:cashier/net/mqtt/mqtt_manager.dart:320:26)
I/flutter ( 3721): │ ⛔ MQTT-->_onSubscribed topic:iot/goods/301105506486579998720015

I/flutter ( 3721): common_utils e  _getDeviceId spDeviceId ===Android_4401000606_LANDI_237ACCH00010  shopId:4401000606 deviceIdMatchShopId:true
I/flutter ( 3721): common_utils e  _getDeviceId deviceId ===Android_4401000606_LANDI_237ACCH00010
I/flutter ( 3721): 1-2024-05-28 17:00:14.528257 -- MqttConnection::onData
I/flutter ( 3721): 1-2024-05-28 17:00:14.529049 -- MqttServerConnection::_onData - message received MQTTMessage of type MqttMessageType.subscribeAck
I/flutter ( 3721): Header: MessageType = MqttMessageType.subscribeAck, Duplicate = false, Retain = false, Qos = MqttQos.atMostOnce, Size = 3
I/flutter ( 3721): SubscribeAck Variable Header: MessageIdentifier={4}
I/flutter ( 3721): Payload: Qos grants [{1}]
I/flutter ( 3721): {{ Grant={MqttQos.atLeastOnce} }}
I/flutter ( 3721): 
I/flutter ( 3721): 1-2024-05-28 17:00:14.529847 -- MqttServerConnection::_onData - message available event fired

I/flutter ( 3721): 1-2024-05-28 17:00:14.530520 -- MqttServerConnection::_onData - message received MQTTMessage of type MqttMessageType.subscribeAck
I/flutter ( 3721): Header: MessageType = MqttMessageType.subscribeAck, Duplicate = false, Retain = false, Qos = MqttQos.atMostOnce, Size = 3
I/flutter ( 3721): SubscribeAck Variable Header: MessageIdentifier={5}
I/flutter ( 3721): Payload: Qos grants [{1}]
I/flutter ( 3721): {{ Grant={MqttQos.atMostOnce} }}
I/flutter ( 3721): 
I/flutter ( 3721): 1-2024-05-28 17:00:14.548198 -- MqttServerConnection::_onData - message available event fired
I/flutter ( 3721): 1-2024-05-28 17:00:14.548977 -- MqttServerConnection::_onData - message received MQTTMessage of type MqttMessageType.subscribeAck
I/flutter ( 3721): Header: MessageType = MqttMessageType.subscribeAck, Duplicate = false, Retain = false, Qos = MqttQos.atMostOnce, Size = 3
I/flutter ( 3721): SubscribeAck Variable Header: MessageIdentifier={6}
I/flutter ( 3721): Payload: Qos grants [{1}]
I/flutter ( 3721): {{ Grant={MqttQos.atMostOnce} }}
I/flutter ( 3721): 
I/flutter ( 3721): 1-2024-05-28 17:00:14.549618 -- MqttServerConnection::_onData - message available event fired
I/flutter ( 3721): 1-2024-05-28 17:00:14.550453 -- MqttConnectionHandlerBase::messageAvailable - message type is MqttMessageType.subscribeAck

I/flutter ( 3721): │ ⛔ MQTT-->__onSubscribed topic:iot/takeout/301105506486579998720015

I/flutter ( 3721): 1-2024-05-28 17:00:14.577031 -- MqttConnectionHandlerBase::messageAvailable - message type is MqttMessageType.subscribeAck

I/flutter ( 3721): │ ⛔ MQTT-->_onSubscribed topic:iot/callNumber/301105506486579998720015

I/flutter ( 3721): 1-2024-05-28 17:00:14.617455 -- MqttConnectionHandlerBase::messageAvailable - message type is MqttMessageType.subscribeAck

I/flutter ( 3721): │ ⛔ MQTT-->_onSubscribed topic:iot/version

I/flutter ( 3721): 1-2024-05-28 17:00:32.439127 -- MqttConnectionKeepAlive::pingRequired
I/flutter ( 3721): 1-2024-05-28 17:00:32.441358 -- MqttConnectionKeepAlive::pingRequired - sending ping request
I/flutter ( 3721): 1-2024-05-28 17:00:32.442112 -- MqttConnectionHandlerBase::sendMessage - MQTTMessage of type MqttMessageType.pingRequest
I/flutter ( 3721): Header: MessageType = MqttMessageType.pingRequest, Duplicate = false, Retain = false, Qos = MqttQos.atMostOnce, Size = 0
I/flutter ( 3721): 1-2024-05-28 17:00:32.445413 -- MqttConnectionKeepAlive::pingRequired - restarting ping timer
I/flutter ( 3721): 1-2024-05-28 17:00:32.471948 -- MqttConnection::onData
I/flutter ( 3721): 1-2024-05-28 17:00:32.473350 -- MqttServerConnection::_onData - message received MQTTMessage of type MqttMessageType.pingResponse
I/flutter ( 3721): Header: MessageType = MqttMessageType.pingResponse, Duplicate = false, Retain = false, Qos = MqttQos.atMostOnce, Size = 0
I/flutter ( 3721): 1-2024-05-28 17:00:32.477315 -- MqttServerConnection::_onData - message available event fired
I/flutter ( 3721): 1-2024-05-28 17:00:32.478228 -- MqttConnectionHandlerBase::messageAvailable - message type is MqttMessageType.pingResponse
I/flutter ( 3721): 1-2024-05-28 17:00:32.484442 -- MqttConnectionKeepAlive::pingResponseReceived

I/flutter ( 3721): │ ⛔ MQTT-->Ping response client callback invoked

I/flutter ( 3721): 1-2024-05-28 17:00:52.446679 -- MqttConnectionKeepAlive::pingRequired
I/flutter ( 3721): 1-2024-05-28 17:00:52.448008 -- MqttConnectionKeepAlive::pingRequired - sending ping request
I/flutter ( 3721): 1-2024-05-28 17:00:52.448487 -- MqttConnectionHandlerBase::sendMessage - MQTTMessage of type MqttMessageType.pingRequest
I/flutter ( 3721): Header: MessageType = MqttMessageType.pingRequest, Duplicate = false, Retain = false, Qos = MqttQos.atMostOnce, Size = 0
I/flutter ( 3721): 1-2024-05-28 17:00:52.450204 -- MqttConnectionKeepAlive::pingRequired - restarting ping timer
I/flutter ( 3721): 1-2024-05-28 17:00:52.557527 -- MqttConnection::onData
I/flutter ( 3721): 1-2024-05-28 17:00:52.558456 -- MqttServerConnection::_onData - message received MQTTMessage of type MqttMessageType.pingResponse
I/flutter ( 3721): Header: MessageType = MqttMessageType.pingResponse, Duplicate = false, Retain = false, Qos = MqttQos.atMostOnce, Size = 0
I/flutter ( 3721): 1-2024-05-28 17:00:52.559308 -- MqttServerConnection::_onData - message available event fired
I/flutter ( 3721): 1-2024-05-28 17:00:52.560244 -- MqttConnectionHandlerBase::messageAvailable - message type is MqttMessageType.pingResponse
I/flutter ( 3721): 1-2024-05-28 17:00:52.560910 -- MqttConnectionKeepAlive::pingResponseReceived

I/flutter ( 3721): │ #0   LoggerUtils.e (package:cashier/utils/logger.dart:71:12)
I/flutter ( 3721): │ #1   MqttManager._log (package:cashier/net/mqtt/mqtt_manager.dart:320:26)
I/flutter ( 3721): │ ⛔ MQTT-->Ping response client callback invoked

I/flutter ( 3721): 1-2024-05-28 17:01:12.452399 -- MqttConnectionKeepAlive::pingRequired
I/flutter ( 3721): 1-2024-05-28 17:01:12.453013 -- MqttConnectionKeepAlive::pingRequired - sending ping request
I/flutter ( 3721): 1-2024-05-28 17:01:12.453383 -- MqttConnectionHandlerBase::sendMessage - MQTTMessage of type MqttMessageType.pingRequest
I/flutter ( 3721): Header: MessageType = MqttMessageType.pingRequest, Duplicate = false, Retain = false, Qos = MqttQos.atMostOnce, Size = 0
I/flutter ( 3721): 1-2024-05-28 17:01:12.454582 -- MqttConnectionKeepAlive::pingRequired - restarting ping timer
I/flutter ( 3721): 1-2024-05-28 17:01:12.496896 -- MqttConnection::onData
I/flutter ( 3721): 1-2024-05-28 17:01:12.497567 -- MqttServerConnection::_onData - message received MQTTMessage of type MqttMessageType.pingResponse
I/flutter ( 3721): Header: MessageType = MqttMessageType.pingResponse, Duplicate = false, Retain = false, Qos = MqttQos.atMostOnce, Size = 0
I/flutter ( 3721): 1-2024-05-28 17:01:12.498725 -- MqttServerConnection::_onData - message available event fired
I/flutter ( 3721): 1-2024-05-28 17:01:12.499915 -- MqttConnectionHandlerBase::messageAvailable - message type is MqttMessageType.pingResponse
I/flutter ( 3721): 1-2024-05-28 17:01:12.500693 -- MqttConnectionKeepAlive::pingResponseReceived

I/flutter ( 3721): │ ⛔ MQTT-->Ping response client callback invoked

I/flutter ( 3721): 1-2024-05-28 17:01:32.455770 -- MqttConnectionKeepAlive::pingRequired
I/flutter ( 3721): 1-2024-05-28 17:01:32.456243 -- MqttConnectionKeepAlive::pingRequired - sending ping request
I/flutter ( 3721): 1-2024-05-28 17:01:32.456679 -- MqttConnectionHandlerBase::sendMessage - MQTTMessage of type MqttMessageType.pingRequest
I/flutter ( 3721): Header: MessageType = MqttMessageType.pingRequest, Duplicate = false, Retain = false, Qos = MqttQos.atMostOnce, Size = 0
I/flutter ( 3721): 1-2024-05-28 17:01:32.459015 -- MqttConnectionKeepAlive::pingRequired - restarting ping timer
I/flutter ( 3721): 1-2024-05-28 17:01:32.484412 -- MqttConnection::onData
I/flutter ( 3721): 1-2024-05-28 17:01:32.485148 -- MqttServerConnection::_onData - message received MQTTMessage of type MqttMessageType.pingResponse
I/flutter ( 3721): Header: MessageType = MqttMessageType.pingResponse, Duplicate = false, Retain = false, Qos = MqttQos.atMostOnce, Size = 0
I/flutter ( 3721): 1-2024-05-28 17:01:32.485846 -- MqttServerConnection::_onData - message available event fired
I/flutter ( 3721): 1-2024-05-28 17:01:32.486569 -- MqttConnectionHandlerBase::messageAvailable - message type is MqttMessageType.pingResponse
I/flutter ( 3721): 1-2024-05-28 17:01:32.487193 -- MqttConnectionKeepAlive::pingResponseReceived

And here is product log: product_log

10:17:52 onAutoReconnect,lastPongTime:2024-05-22 10:17:22  
10:17:52 error:SocketException: Software caused connection abort (OS Error: Software caused connection abort, errno = 103), address = mqtt-cn-i7m2pv29604.mqtt.aliyuncs.com, port = 51576, stackTrace:
10:17:53 call onAutoReconnect, lastPongTime:2024-05-22 10:17:22 Ping begin
Ping start:eshop-mch.xgd.com
Ping:eshop-mch.xgd.com result:[PingError(response:null, error:unknownHost)]
Ping start:www.baidu.com
Ping:www.baidu.com result:[PingError(response:null, error:unknownHost)]
ping end
10:17:53  MqttEngine.clear 
10:17:53  disconnect 
10:17:53  onDisconnected 

10:18:23 MqttEngine.initAndConnect 
10:18:23 MqttManager ,server:mqtt-cn-i7m2pv29604.mqtt.aliyuncs.com
 port:1883
 clientIdentifier:GID_iot_print@@@301116085457332657356861
 username:Signature|LTAI5tNpshgywqkWZhLiL7Yb|mqtt-cn-i7m2pv29604 
 password:OYA4wTtdnfrdw7OnjfF6wcgNrpg= 
10:18:23 MQTT connect 
10:18:23 mqtt onConnected 

10:18:23 _onSubscribed topic:iot/print/301116085457332657356861 
10:18:23 _onSubscribed topic:iot/version/2 
10:18:24 _onSubscribed topic:iot/order/301116085457332657356861 
10:18:24 _onSubscribed topic:iot/goods/301116085457332657356861 
10:18:24 _onSubscribed topic:iot/takeout/301116085457332657356861 
10:18:24 _onSubscribed topic:iot/callNumber/301116085457332657356861 
10:18:24 _onSubscribed topic:iot/version 
10:18:34 didPush: /orderDetailMain
10:23:20 didPop: /orderDetailMain
10:24:32 didPush: /sellClearView
10:24:33 didPop: /sellClearView
shamblett commented 3 months ago

Your client log above seems to start at 17:00 on the 28/05 it looks like normal operation, there is no auto connect sequence in it or any errors that I can see.

The errors in your other logs seem to be on 22/05 at 10:17.

I need a client log from when the error occurred, in the case above from say 10:15 on 22/05

BIG-BEARC commented 3 months ago

Sorry, I can't get the production MQTT log information; I can only obtain the production screenshot information ,When encountering the SocketException: Software caused connection abort exception, there will be issues with MQTT reconnection. At this point, two connections will contend for resources, leading to continuous reconnection attempts on each side.

shamblett commented 3 months ago

Sounds as though you are calling connect on the client before disconnect has been called, this will cause your reported problem. It seems you are using auto reconnect, this will try and reconnect forever you must call disconnect to stop this before calling connect again. Best I can do without logs.

mehmetgencdal commented 3 months ago

Same issue. Any solutions?

BIG-BEARC commented 3 months ago

Sounds as though you are calling connect on the client before disconnect has been called, this will cause your reported problem. It seems you are using auto reconnect, this will try and reconnect forever you must call disconnect to stop this before calling connect again. Best I can do without logs.

I am certain that I actively called disconnect before reconnecting. Here is the code I used for the call

  static Future reConnect() {
    clear();
    return Future.delayed(const Duration(seconds: 30), ()  {
       MqttEngine().initAndConnect();
    });
  }

 void clear() {
    cancelTimer();
    _instance = null;
    disconnect();
    _mqttClient = null;
    _isConnectSuccess = false;
    _reConnectNum = 0;
    _lastTime = DateTime.now();
  }

  disconnect() {
    if (_mqttClient?.connectionStatus?.state == MqttConnectionState.connected || _mqttClient?.connectionStatus?.state == MqttConnectionState.connecting) {
      _mqttClient?.disconnect();
    }
  }

And after calling disconnect, I waited for 30 seconds before re-establishing the connection. Then I collected this exception error(error:Bad state: Cannot add new events after calling close) on the logging platform. If I don't do this, there will be two MQTT connections continuously reconnecting, conflicting with each other, and preventing the proper reception of push notifications.

Thanks again for wasting your time

shamblett commented 3 months ago

Ok still can't go any further without the logs, I need to see exactly what is happening as far as the client is concerned not what everyone thinks is happening