-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
LateInitializationError: Field 'messageStream' has not been initialized. #16
Conversation
The onAutoReconnected event handler was never set tot the connection handler.
When connecting fails on first call of connect() on the MQTT client. Then you invoke the doAutoReconnect() method (and also set the autoReconnect property to true). When it connects, the server connections don't have a readWrapper and messagStream, which result in exceptions.
I'm not sure why you need to recreate readWrapper and messageStream in the connectAuto method, these are created in the connect method which you must call first and as far as I can see never subsequently destroyed. Your use case seems a little odd, you can't invoke autoConnect until connect has worked. Another way to do this is to move the setting of readWrapper and messageStream to the top of the connect method, i.e. they are in place before we start the socket connect, not after so they should persist from then on. |
The objects are created when the socket has a connection. When there is no successfull connection, these objects aren't created. Moving them up, is a perfect solution. Why not make those fields final and initialised? I invoke the doAutoConnect when the connect() fails. So the code is trying to attempt to connect. The event handlers are used to give information back to the logs. I'm creating a program that needs the MQTT broker to work. And it should solve it's connection without user interaction. |
I see what you are saying, yes we could make them final and initialised. OK i understand what you are trying to do now. |
I can do it tonight. I revert the commit and make those fields final and remove them in the connect and autoConnect methods. ok? |
Yep, sounds good to me, thanks. |
Initialize the readWrapper and messageStream in the base connection class. Removed the creation of those objects in the connection classes in the socket callbacks.
; too much
Package re published now at version 3.1.2 |
When you have a Dart program which starts and connects to a MQTT broker. But the broker is offline, so you start the autoConnect proces.
When the MQTT broker is back online, it connects. But an exception is thrown because the messageStream isn't initialized. The late property is only set in the connect() method and should also be set in the connectAuto().
The mqtt_browser_ws_connection.dart is correct. The mqtt_server_*_connection.dart not.
Also the event handler onAutoReconnected isn't set and by this never called.