shamblett / mqtt_client

A server and browser based MQTT client for dart
Other
552 stars 179 forks source link

RangeError (index): Invalid value: Not in inclusive range #496

Closed josh4500 closed 7 months ago

josh4500 commented 11 months ago

I keep getting the error log below after keeping the connection for a longer period of time.

E/flutter (14491): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: RangeError (index): Invalid value: Not in inclusive range 0..6: 32
E/flutter (14491): #0      _Array.[] (dart:core-patch/array.dart:10:36)
E/flutter (14491): #1      MqttVariableHeader.readReturnCode (package:mqtt_client/src/messages/mqtt_client_mqtt_variable_header.dart:183:46)
E/flutter (14491): #2      MqttConnectAckVariableHeader.readFrom (package:mqtt_client/src/messages/connectack/mqtt_client_mqtt_connect_ack_variable_header.dart:35:5)
E/flutter (14491): #3      new MqttVariableHeader.fromByteBuffer (package:mqtt_client/src/messages/mqtt_client_mqtt_variable_header.dart:51:5)
E/flutter (14491): #4      new MqttConnectAckVariableHeader.fromByteBuffer (package:mqtt_client/src/messages/connectack/mqtt_client_mqtt_connect_ack_variable_header.dart:17:15)
E/flutter (14491): #5      MqttConnectAckMessage.readFrom (package:mqtt_client/src/messages/connectack/mqtt_client_mqtt_connect_ack_message.dart:36:51)
E/flutter (14491): #6      new MqttConnectAckMessage.fromByteBuffer (package:mqtt_client/src/messages/connectack/mqtt_client_mqtt_connect_ack_message.dart:25:5)
E/flutter (14491): #7      MqttMessageFactory.getMessage (package:mqtt_client/src/messages/mqtt_client_mqtt_message_factory.dart:21:41)
E/flutter (14491): #8      MqttMessage.createFrom (package:mqtt_client/src/messages/mqtt_client_mqtt_message.dart:51:42)
E/flutter (14491): #9      MqttServerConnection.onData (package:mqtt_client/src/connectionhandling/server/mqtt_client_mqtt_server_connection.dart:58:27)
E/flutter (14491): #10     _RootZone.runUnaryGuarded (dart:async/zone.dart:1594:10)
E/flutter (14491): #11     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:339:11)
E/flutter (14491): #12     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:271:7)
E/flutter (14491): #13     _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:784:19)
E/flutter (14491): #14     _StreamController._add (dart:async/stream_controller.dart:658:7)
E/flutter (14491): #15     _StreamController.add (dart:async/stream_controller.dart:606:5)
E/flutter (14491): #16     _Socket._onData (dart:io-patch/socket_patch.dart:2447:41)
E/flutter (14491): #17     _RootZone.runUnaryGuarded (dart:async/zone.dart:1594:10)
E/flutter (14491): #18     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:339:11)
E/flutter (14491): #19     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:271:7)
E/flutter (14491): #20     _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:784:19)
E/flutter (14491): #21     _StreamController._add (dart:async/stream_controller.dart:658:7)
E/flutter (14491): #22     _StreamController.add (dart:async/stream_controller.dart:606:5)
E/flutter (14491): #23     new _RawSocket.<anonymous closure> (dart:io-patch/socket_patch.dart:1936:33)
E/flutter (14491): #24     _NativeSocket.issueReadEvent.issue (dart:io-patch/socket_patch.dart:1379:14)
E/flutter (14491): #25     _microtaskLoop (dart:async/schedule_microtask.dart:40:21)
E/flutter (14491): #26     _startMicrotaskLoop (dart:async/schedule_microtask.dart:49:5)
josh4500 commented 11 months ago

Error does not appear on reconnection, just only after a long connection period.

shamblett commented 11 months ago

The return codes as defined in the MQTT spec are -

0  0x00 Connection Accepted  Connection accepted
1  0x01 Connection Refused, unacceptable protocol version The Server does not support the level of the MQTT 
    protocol requested by the Client
2  0x02 Connection Refused, identifier rejected The Client identifier is correct UTF-8 but not allowed by the Server
3  0x03 Connection Refused, Server unavailable The Network Connection has been made but the MQTT service is 
   unavailable
4 0x04 Connection Refused, bad user name or password The data in the user name or password is malformed
5  0x05 Connection Refused, not authorized The Client is not authorized to connect
6-255  Reserved for future use

As you can see the read value of 32 is reserved for future use and shouldn't be sent by the broker, it either is being sent or the message itself has somehow been corrupted.

lihehehehe commented 9 months ago

I have same error, so how to fix that?

shamblett commented 9 months ago

As I said above, its either your broker or your network connection.