-
Notifications
You must be signed in to change notification settings - Fork 15
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
Detect Websocket is connected or disconnected #20
Comments
Hi there! I've released a RC version, can you please test it out and let me know if this fixes your issue? To use the RC version, you can try changing the pubnub: 3.0.0-rc Alternatively, change your pubnub:
git:
url: [email protected]:pubnub/dart.git
ref: v3.0.0-rc In this new version, there should be a new method on the Please keep in mind, that with this new version, some imports may have changed (especially for Thanks for your cooperation! |
Thanks for this @are we managed to update using the first option. Other then reconnection we experienced breaking changes in ChannelGroup and fetching messageActions from history. While we spend a few hours fixing them but we got stuck with the following errors while trying to subscribe: 1 st ERROR****** selfSubscription = client.subscribe( [ERROR:flutter/lib/ui/ui_dart_state.cc(166)] Unhandled Exception: type 'EfficientLengthMappedIterable<String, String>' is not a subtype of type 'Set' If we remove withPresence: true, then this error is not coming. 2 nd ERROR***** selfSubscription = client.subscribe(channelGroups: channelGroupSet); [ERROR:flutter/lib/ui/ui_dart_state.cc(166)] Unhandled Exception: NoSuchMethodError: The method 'contains' was called on null. 3rd ERROR***** |
The main item we were to try was @are can you write a small para explaining how this new option is to be used, as per your comments > This method will reconnect all long-running connections if necessary automatically. You can call it any time you need. As it says it will automatically reconnect, do we need to do anything in our code while initializing the client or subscribing for the automatic reconnection to work? Also if we have to call this manually please give some guidance or example. Our requirement is
|
To fix those errors, please update When it comes to using |
Thanks @are we have managed to upgrade and first 2 out of the 3 exceptions are taken care off, we are able to subscribe withPresence True and channelGroup. For 3rd error steps to reproduce are same as mentioned in issue 19. We are awaiting your guidance on reconnect and connection reliability. |
So the issue is a bit more complex and its not a problem with the PubNub SDK itself. Take a look here: flutter/flutter#33427 Basically, Debugger reports some exceptions as unhandled, but in reality they are handled correctly. This issue only happens in development debug mode, when the application is build for production, there is no issue with running the code. This problem happens because of the Dio library that we use for Http, and multiple people have the same problem with other libraries as well. To circumvent this problem, you need to uncheck |
Will try this tomorrow and report back. Regarding reconnection based on our study we need to understand it at 3 levels
We need help to understand how SDK takes care of Websocket part and what should we do when initiating the client and subscription so that automatic reconnection is taken care by SDK, secondly in certain situations we need to run History Fetching before reconnection to ensure all messages are retrieved before connection is established if the client was disconnected for more than 10-12 mins. Other scenario is when channel is added or removed we need to resubscribe/reconnect with new set. Key options available from connection perspective are subscribe, dispose, reconnect, pause, resume what we need to understand is when to use what and are we missing something. Hence few examples will be very useful. |
Great news - I think I have been able to fix the issues with reconnection in Android. It's available in How reconnection worksIn the SDK we differentiate between two types of network requests:
Just to be clear: we are not using
Meanwhile, when you are making a When it comes to initializing the client and subscription there is only one thing you need to do to enable reconnection and retrial - and that is to pass in the import 'package:pubnub/pubnub.dart';
import 'package:pubnub/networking.dart';
var client = PubNub(
networking:
NetworkingModule(retryPolicy: RetryPolicy.exponential(maxRetries: 10)),
defaultKeyset: myKeyset,
); You can either use the builtin Using History to retrieve missed messages:In general, Adding or removing channels
var sub = pubnub.subscribe(channels: {'my1', 'my2'});
// some time later
await sub.cancel();
sub = pubnub.subscribe(channels: sub.channels.difference({'my1'})); // subtracts 'my1' channel => result {'my2'}
// some time later
await sub.cancel();
sub = pubnub.subscribe(channels: sub.channels.union({'my3'})); // adds 'my3' channel => result {'my2', 'my3'} How to use
|
Appreciate your help @are we are now using v3.0.0-rc.2 Reconnect is working and we are also able to check if SDK connection is up or down. Here is one observation:
We are still testing but we have been able to reproduce this few times. |
So this is the bigger issue with the reconnection in general: unless we do some action and that action fails, we cannot know that the network is down. You can try tweaking the RetryPolicy or using the |
We managed to run a few more tests and below are the observations, the reason to report here is despite manually calling reconnect it is taking time for reconnection and the bigger worry is when the reconnection happens getting pending messages from the server is quite inconsistent (sometimes all messages missed, partial messages missed and no messages missed). ************ When we are not calling reconnection but depending on SDK to automatically reconnect************************* 10 Messages Received out of 10 sent before reconnection (No issues with the number of messages received) 100 Messages Received out of 110 sent before reconnection (No issues with the number of messages received) ************ When we are calling reconnection upon network availability************************* 24 Messages received out of 50 sent before reconnect - Partial messages missed No Messages Received Out of 50 sent before reconnect - All messages missed All 50 Messages received out of 50 sent before reconnect - No messages missed All 50 Messages received out of 50 sent before reconnect - No messages missed No Messages Received out of 110 sent before reconnect - All messages missed //Manual Reconnection code. //Print log for SDK Connection is Up Or Down This is a different observation and seems to be working as planned but just want to reconfirm, the networkIsConnected will only switch from false to true and true to false if the state changes, but if the state is false and the internet goes on and off it will not print false again because it was not set to true when the internet was recovered. It is a different matter of why it did not turn true upon internet availability, below are the logs. I/flutter ( 3077): NetworkIsConnected false at 2020-09-30 19:50:13.961787 |
Further to yesterday's message, did testing for getting pending messages upon automatic reconnection. We are also publishing a dummy typing signal on UUID channel to generate some traffic for connection check to work. As soon as this event is sent NetworkIsConnected shows true. But pending messages either take 25-45 secs to start coming or are missed totally. We are testing all of this within 2-3 or max 5 mins cycles so we are surely not exceeding the cache time of 10-16 mins on server. We request if you can test the reliability of getting messages from server upon reconnection, seems something worth investigating either in SDK or our code. **************Log when all messages missed No messages received even after NetworkIsConnected returned true. I/flutter (17857): NetworkIsConnected false at 2020-10-01 13:04:56.770834 |
Due to unreliability of getting missed messages upon reconnection, we have introduced history fetching as soon as device internet is up. Due to history event networkIsConnected is set to true and now we are getting messages from history and repeat of partial messages from subscription, though we are ignoring duplicates but it is unwanted and confusing. |
Thanks for diving deep into this. This is something that will require a bit more time to investigate. |
@devopsokdone the fix to the original issue has been released in v3.0.0. I will close this issue for clarity, but don't worry - the reliability issues are on our internal checklist. Feel free to open a new issue for that if you want to have it tracked. |
We have upgraded the SDK to v 2.0.1 and imported the networking module with retry policy while making the connection as explained in response to question in issue 19.
But if the app is open and long poll interval is over the Websocket disconnects which is correct also sometimes it disconnects if we switch between apps or when network comes back after brief disconnection.
Our question is, is there a way to detect if socket connection is connected, connecting or disconnected is there a way to check and trigger reconnection if socket is disconnected.
Currently what we do is dispose and subscribe whenever app comes in foreground, is restarted or internet state changes but for long poll disconnection we don't have a way to handle as well as we don't want to do the unnecessary reconnection if the connection is already alive.
The text was updated successfully, but these errors were encountered: