Closed mehtahardikr closed 4 years ago
Hi there! Thanks for reporting the issue.
This is the expected default behavior - if not configured, the PubNub SDK will fail when any of its request fail.
If you want to enable retrying/reconnection, you need to pass in RetryPolicy
into the NetworkingModule
when initializing PubNub
like so:
import 'package:pubnub/pubnub.dart';
import 'package:pubnub/networking.dart';
var pubnub = PubNub(
networking: NetworkingModule(
retryPolicy: RetryPolicy.exponential(maxRetries: 10)),
defaultKeyset:
Keyset(subscribeKey: 'demo', publishKey: 'demo', uuid: UUID('demo')),
);
@are : I am using the same code. But still its throws that exception. Let me know is anything need to change or missing from my side.
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
version to 3.0.0-rc
like so:
pubnub: 3.0.0-rc
Alternatively, change your pubnub
dependency in pubspec.yaml
to the following to use latest github version:
pubnub:
git:
url: git@github.com:pubnub/dart.git
ref: v3.0.0-rc
Please keep in mind, that with this new version, some imports may have changed (especially for StreamLogger
or RetryPolicy
) - they have been moved to separate module imports (package:pubnub/logging.dart
and package:pubnub/networking.dart
respectively).
Thanks for your cooperation!
hey @are: i have checked with that provided dependency.
and facing this error while turns off internet.
E/flutter (10672): [ERROR:flutter/lib/ui/ui_dart_state.cc(166)] Unhandled Exception: PubNubException: request failed
[ ] E/flutter (10672): #0 new PubNubException (package:pubnub/src/core/exceptions.dart:9)
[ ] E/flutter (10672): #1 new PubNubRequestOtherException (package:pubnub/src/core/net/exceptions.dart:24)
[ ] E/flutter (10672): #2 RequestHandler.response (package:pubnub/src/net/request_handler.dart:31)
[ ] E/flutter (10672): <asynchronous suspension>
[ ] E/flutter (10672): #3 withCancel.complete (package:pubnub/src/subscribe/subscribe_loop/subscribe_loop.dart)
[ ] E/flutter (10672): <asynchronous suspension>
[ ] E/flutter (10672):
[ ] E/flutter (10672):
i am using same code
Keyset key = Keyset(subscribeKey: 'demo', publishKey: 'demo', uuid: UUID('demo'));
key.heartbeatInterval = 5;
key.presenceTimeout =30;
// Create PubNub instance with default keyset.
var pubnub = PubNub(defaultKeyset: key , networking: NetworkingModule(
retryPolicy: RetryPolicy.exponential(maxRetries: 10)));
var subscription = await pubnub.subscribe(channels: {'test_channel'});
subscription.messages.listen((event) {
print("new Message ${event.payload}");
} , onDone: (){
print("on done");
});
and one more thing is
is this part removed ?
pubnub.supervisor.events.listen((event) {
// Check NetworkIsDownEvent OR NetworkIsUpEvent
});
Here are the logs using logger, may helpfuli to you
I/flutter (13756): [2020-09-26 11:50:47.760293] (info) myLogger.pubnub.networking.request_handler: (6) Request failed (DioError [DioErrorType.DEFAULT]: HttpException: , uri =
https://ps.pndsn.com/v2/subscribe/demo/test_channel/0?pnsdk=PubNub-Dart%2F3.0.0&tt=16011012391806360&tr=7&uuid=demo, HttpException: , uri =
https://ps.pndsn.com/v2/subscribe/demo/test_channel/0?pnsdk=PubNub-Dart%2F3.0.0&tt=16011012391806360&tr=7&uuid=demo)
[ ] I/flutter (13756): [2020-09-26 11:50:47.771269] (info) myLogger.pubnub.networking.request_handler: (6) Resource released...
[ ] I/flutter (13756): [2020-09-26 11:50:47.772069] (silly) myLogger.pubnub.subscribe.subscribe_loop: Cancelling the handler...
[ ] I/flutter (13756): [2020-09-26 11:50:47.772575] (warning) myLogger.pubnub.subscribe.subscribe_loop: An exception has occured while running a subscribe fiber (retry #1).
[ +20 ms] E/flutter (13756): [ERROR:flutter/lib/ui/ui_dart_state.cc(166)] Unhandled Exception: PubNubException: request failed
[ ] E/flutter (13756): #0 new PubNubException (package:pubnub/src/core/exceptions.dart:9)
[ ] E/flutter (13756): #1 new PubNubRequestOtherException (package:pubnub/src/core/net/exceptions.dart:24)
[ ] E/flutter (13756): #2 RequestHandler.response (package:pubnub/src/net/request_handler.dart:31)
[ ] E/flutter (13756): <asynchronous suspension>
[ ] E/flutter (13756): #3 withCancel.complete (package:pubnub/src/subscribe/subscribe_loop/subscribe_loop.dart)
[ ] E/flutter (13756): <asynchronous suspension>
[ ] E/flutter (13756):
[ ] E/flutter (13756):
[ ] I/flutter (13756): [2020-09-26 11:50:47.792170] (silly) myLogger.pubnub.subscribe.subscribe_loop: State has been updated.
hope this may help you. let me know. is further support needed.
Flutter version 1.20.4
Dart version 2.9.2
Android Studio 4.0.1
these logs after by temporary disabling "Break on Exceptions". so you can get idea.
Thank you !
Thanks for the details! I really appreciate it.
What seems to be the problem is that the supervisor
does not recognize the reason for the failure. When that happens, it has no idea how to proceed and throws the error.
Can you let me know how do you simulate the network disconnection? If I replicate it, I can add it into the diagnostics and strategy modules for network to handle that issue properly.
@are : just init pubnub config , subscribe the channel , send message from pubunb console to check channel receive message or not. After sometime just turn off device internet and you will see the error. Internet may be like wifi or mobile data. Hope this will help you.
Hi! Please take a look at this comment: https://github.com/pubnub/dart/issues/20#issuecomment-700818107.
TL;DR: There is an issue with Flutter Debugger that breaks the application when some handled exceptions happen (this should not happen, but Flutter team refuses to fix it for now). The only way to circumvent this is to disable Break on Unhandled Exceptions.
I have isolated additional types of exceptions that should trigger retry and I've managed to run it in the Android simulator successfully. I will let you know when I deploy fixed version.
I've uploaded PubNub SDK version '3.0.0-rc.2'. Can you test it out? Remember to keep Break on Unhandled Exceptions unchecked.
@are : I have checked and seems to be good here are the logs after unchecking of 'Break on Exceptions'
I/flutter (21199): [2020-09-30 09:44:00.218821] (info) myLogger.pubnub.networking.request_handler: (5) Request failed (DioError [DioErrorType.DEFAULT]: HttpException: , uri =
https://ps.pndsn.com/v2/subscribe/demo/test_channel/0?pnsdk=PubNub-Dart%2F3.0.0&tt=16014392300318424&tr=7&uuid=demo, HttpException: , uri =
https://ps.pndsn.com/v2/subscribe/demo/test_channel/0?pnsdk=PubNub-Dart%2F3.0.0&tt=16014392300318424&tr=7&uuid=demo)
[ +1 ms] I/flutter (21199): [2020-09-30 09:44:00.226338] (info) myLogger.pubnub.networking.request_handler: (5) Resource released...
[ ] I/flutter (21199): [2020-09-30 09:44:00.226768] (silly) myLogger.pubnub.subscribe.subscribe_loop: Cancelling the handler...
[ +3 ms] I/flutter (21199): [2020-09-30 09:44:00.227102] (warning) myLogger.pubnub.subscribe.subscribe_loop: An exception has occured while running a subscribe fiber (retry #1).
[ ] I/flutter (21199): [2020-09-30 09:44:00.231058] (silly) myLogger.pubnub.subscribe.subscribe_loop: Possible reason found: Instance of 'UnknownHttpExceptionDiagnostic'
[ ] I/flutter (21199): [2020-09-30 09:44:00.231810] (verbose) myLogger.pubnub.core.supervisor.signals: Signaled that network is down.
[ ] I/flutter (21199): [2020-09-30 09:44:00.232608] (silly) myLogger.pubnub.subscribe.subscribe_loop: State has been updated.
[+1910 ms] I/flutter (21199): [2020-09-30 09:44:02.166232] (silly) myLogger.pubnub.subscribe.subscribe_loop: Starting new loop iteration.
[ ] I/flutter (21199): [2020-09-30 09:44:02.167022] (info) myLogger.pubnub.networking.request_handler: (6) Awaiting for resource...
[ ] I/flutter (21199): [2020-09-30 09:44:02.167456] (info) myLogger.pubnub.networking.request_handler: (6) Resource obtained.
[ ] I/flutter (21199): [2020-09-30 09:44:02.167823] (info) myLogger.pubnub.networking.request_handler: (6) Starting request to
https://ps.pndsn.com/v2/subscribe/sub-c-6a8921e8-e846-11ea-9d1c-16efd2dbfec5/test_channel/0?pnsdk=PubNub-Dart%2F3.0.0&tt=16014392300318424&tr=7&uuid=demo...
[ +16 ms] I/flutter (21199): [2020-09-30 09:44:02.185284] (info) myLogger.pubnub.networking.request_handler: (6) Request failed (DioError [DioErrorType.DEFAULT]: SocketException: Failed host lookup: 'ps.pndsn.com' (OS
Error: No address associated with hostname, errno = 7), SocketException: Failed host lookup: 'ps.pndsn.com' (OS Error: No address associated with hostname, errno = 7))
[ +3 ms] I/flutter (21199): [2020-09-30 09:44:02.185955] (info) myLogger.pubnub.networking.request_handler: (6) Resource released...
[ ] I/flutter (21199): [2020-09-30 09:44:02.187754] (silly) myLogger.pubnub.subscribe.subscribe_loop: Cancelling the handler...
[ ] I/flutter (21199): [2020-09-30 09:44:02.188417] (warning) myLogger.pubnub.subscribe.subscribe_loop: An exception has occured while running a subscribe fiber (retry #2).
[ ] I/flutter (21199): [2020-09-30 09:44:02.189073] (silly) myLogger.pubnub.subscribe.subscribe_loop: Possible reason found: Instance of 'HostLookupFailedDiagnostic'
[+2826 ms] I/flutter (21199): [2020-09-30 09:44:05.005130] (silly) myLogger.pubnub.subscribe.subscribe_loop: Starting new loop iteration.
[ ] I/flutter (21199): [2020-09-30 09:44:05.010108] (info) myLogger.pubnub.networking.request_handler: (7) Awaiting for resource...
[ ] I/flutter (21199): [2020-09-30 09:44:05.010973] (info) myLogger.pubnub.networking.request_handler: (7) Resource obtained.
[ ] I/flutter (21199): [2020-09-30 09:44:05.011807] (info) myLogger.pubnub.networking.request_handler: (7) Starting request to
https://ps.pndsn.com/v2/subscribe/demo/test_channel/0?pnsdk=PubNub-Dart%2F3.0.0&tt=16014392300318424&tr=7&uuid=demo...
[ +18 ms] I/flutter (21199): [2020-09-30 09:44:05.033010] (info) myLogger.pubnub.networking.request_handler: (7) Request failed (DioError [DioErrorType.DEFAULT]: SocketException: Failed host lookup: 'ps.pndsn.com' (OS
Error: No address associated with hostname, errno = 7), SocketException: Failed host lookup: 'ps.pndsn.com' (OS Error: No address associated with hostname, errno = 7))
[ +1 ms] I/flutter (21199): [2020-09-30 09:44:05.033839] (info) myLogger.pubnub.networking.request_handler: (7) Resource released...
[ ] I/flutter (21199): [2020-09-30 09:44:05.034174] (silly) myLogger.pubnub.subscribe.subscribe_loop: Cancelling the handler...
[ ] I/flutter (21199): [2020-09-30 09:44:05.034457] (warning) myLogger.pubnub.subscribe.subscribe_loop: An exception has occured while running a subscribe fiber (retry #3).
[ ] I/flutter (21199): [2020-09-30 09:44:05.034927] (silly) myLogger.pubnub.subscribe.subscribe_loop: Possible reason found: Instance of 'HostLookupFailedDiagnostic'
[+4162 ms] I/flutter (21199): [2020-09-30 09:44:09.195422] (silly) myLogger.pubnub.subscribe.subscribe_loop: Starting new loop iteration.
[ ] I/flutter (21199): [2020-09-30 09:44:09.197054] (info) myLogger.pubnub.networking.request_handler: (8) Awaiting for resource...
[ ] I/flutter (21199): [2020-09-30 09:44:09.197783] (info) myLogger.pubnub.networking.request_handler: (8) Resource obtained.
[ ] I/flutter (21199): [2020-09-30 09:44:09.198664] (info) myLogger.pubnub.networking.request_handler: (8) Starting request to
https://ps.pndsn.com/v2/subscribe/sub-c-6a8921e8-e846-11ea-9d1c-16efd2dbfec5/test_channel/0?pnsdk=PubNub-Dart%2F3.0.0&tt=16014392300318424&tr=7&uuid=demo...
[ +23 ms] I/flutter (21199): [2020-09-30 09:44:09.221201] (info) myLogger.pubnub.networking.request_handler: (8) Request failed (DioError [DioErrorType.DEFAULT]: SocketException: Failed host lookup: 'ps.pndsn.com' (OS
Error: No address associated with hostname, errno = 7), SocketException: Failed host lookup: 'ps.pndsn.com' (OS Error: No address associated with hostname, errno = 7))
[ +1 ms] I/flutter (21199): [2020-09-30 09:44:09.222027] (info) myLogger.pubnub.networking.request_handler: (8) Resource released...
[ ] I/flutter (21199): [2020-09-30 09:44:09.222361] (silly) myLogger.pubnub.subscribe.subscribe_loop: Cancelling the handler...
[ ] I/flutter (21199): [2020-09-30 09:44:09.222639] (warning) myLogger.pubnub.subscribe.subscribe_loop: An exception has occured while running a subscribe fiber (retry #4).
[ ] I/flutter (21199): [2020-09-30 09:44:09.223118] (silly) myLogger.pubnub.subscribe.subscribe_loop: Possible reason found: Instance of 'HostLookupFailedDiagnostic'
[+5315 ms] D/ViewRootImpl@7b108cf[MainActivity](21199): MSG_WINDOW_FOCUS_CHANGED 1
[+3208 ms] I/flutter (21199): [2020-09-30 09:44:17.747121] (silly) myLogger.pubnub.subscribe.subscribe_loop: Starting new loop iteration.
[ ] I/flutter (21199): [2020-09-30 09:44:17.748092] (info) myLogger.pubnub.networking.request_handler: (9) Awaiting for resource...
[ +3 ms] I/flutter (21199): [2020-09-30 09:44:17.748751] (info) myLogger.pubnub.networking.request_handler: (9) Resource obtained.
[ ] I/flutter (21199): [2020-09-30 09:44:17.749289] (info) myLogger.pubnub.networking.request_handler: (9) Starting request to
https://ps.pndsn.com/v2/subscribe/sub-c-6a8921e8-e846-11ea-9d1c-16efd2dbfec5/test_channel/0?pnsdk=PubNub-Dart%2F3.0.0&tt=16014392300318424&tr=7&uuid=demo...
[+5800 ms] I/flutter (21199): [2020-09-30 09:44:23.546345] (info) myLogger.pubnub.networking.request_handler: (9) Request succeed!
[ +8 ms] I/flutter (21199): [2020-09-30 09:44:23.547511] (info) myLogger.pubnub.networking.request_handler: (9) Resource released...
[ ] I/flutter (21199): [2020-09-30 09:44:23.557413] (verbose) myLogger.pubnub.core.supervisor.signals: Signaled that network is up.
[ ] I/flutter (21199): [2020-09-30 09:44:23.558075] (silly) myLogger.pubnub.subscribe.subscribe_loop: State has been updated.
[ ] I/flutter (21199): [2020-09-30 09:44:23.558969] (silly) myLogger.pubnub.subscribe.subscribe_loop: Result: timetoken 16014392642356233, new messages: 1
[ ] I/flutter (21199): new Message {text: hey}
[ +2 ms] I/flutter (21199): [2020-09-30 09:44:23.565007] (silly) myLogger.pubnub.subscribe.subscribe_loop: Updating the state...
[ ] I/flutter (21199): [2020-09-30 09:44:23.565485] (silly) myLogger.pubnub.subscribe.subscribe_loop: State has been updated.
[ ] I/flutter (21199): [2020-09-30 09:44:23.565957] (silly) myLogger.pubnub.subscribe.subscribe_loop: Starting new loop iteration.
[ ] I/flutter (21199): [2020-09-30 09:44:23.566609] (info) myLogger.pubnub.networking.request_handler: (10) Awaiting for resource...
[ +16 ms] I/flutter (21199): [2020-09-30 09:44:23.567021] (info) myLogger.pubnub.networking.request_handler: (10) Resource obtained.
[ ] I/flutter (21199): [2020-09-30 09:44:23.569335] (info) myLogger.pubnub.networking.request_handler: (10) Starting request to
https://ps.pndsn.com/v2/subscribe/sub-c-6a8921e8-e846-11ea-9d1c-16efd2dbfec5/test_channel/0?pnsdk=PubNub-Dart%2F3.0.0&tt=16014392642356233&tr=7&uuid=demo...
[+4658 ms] I/flutter (21199): [2020-09-30 09:44:28.242224] (info) myLogger.pubnub.networking.request_handler: (10) Request succeed!
[ +2 ms] I/flutter (21199): [2020-09-30 09:44:28.243197] (info) myLogger.pubnub.networking.request_handler: (10) Resource released...
[ +2 ms] I/flutter (21199): [2020-09-30 09:44:28.247968] (silly) myLogger.pubnub.subscribe.subscribe_loop: Result: timetoken 16014392689128211, new messages: 1
[ +2 ms] I/flutter (21199): new Message {text: hey}
[ ] I/flutter (21199): [2020-09-30 09:44:28.250473] (silly) myLogger.pubnub.subscribe.subscribe_loop: Updating the state...
[ +4 ms] I/flutter (21199): [2020-09-30 09:44:28.252285] (silly) myLogger.pubnub.subscribe.subscribe_loop: State has been updated.
[ ] I/flutter (21199): [2020-09-30 09:44:28.253909] (silly) myLogger.pubnub.subscribe.subscribe_loop: Starting new loop iteration.
[ +5 ms] I/flutter (21199): [2020-09-30 09:44:28.256002] (info) myLogger.pubnub.networking.request_handler: (11) Awaiting for resource...
[ ] I/flutter (21199): [2020-09-30 09:44:28.256657] (info) myLogger.pubnub.networking.request_handler: (11) Resource obtained.
[ ] I/flutter (21199): [2020-09-30 09:44:28.258482] (info) myLogger.pubnub.networking.request_handler: (11) Starting request to
https://ps.pndsn.com/v2/subscribe/demo/test_channel/0?pnsdk=PubNub-Dart%2F3.0.0&tt=16014392689128211&tr=7&uuid=demo...
i have init pubnub , sunscribe the channel, send message from console, now turn off internet of phone/device and seems to be its trying to reconnect and after turning back internet on , send message from console and received as well.
Now the question is about internet down/up or connect/disconnect callback ? Means monitioring of pubnub conection like PNCategories that we have for other sdks like java , etc. i didn't find that.Can you help me with that ?
I'm glad that reconnection is working properly!
You can subscribe to the different pubnub.signals
streams to receive events when the network goes up or down:
pubnub.signals.networkIsUp
will emit when reconnection was successful,pubnub.signals.networkIsDown
will emit when network down was detected,pubnub.signals.networkIsConnected
will emit each time network status changes with a boolean telling you if network is up or down.So just to give an example:
pubnub.signals.networkIsConnected.listen((isUp) {
if (isUp) {
print('network reconnected');
} else {
print('network disconnected');
}
});
@are thanks for that ,one more thing , still i need to disbale break on exceptions option for this or its okay to use without doing this ?
Hi! Yes, you need to disable that unfortunately. There may be a point in a future where that will be fixed by flutter, but we cannot do anything about that for now.
@are : okay thanks for that. When you going to release this new update ?
@mehtahardikr as soon as we finish the internal review process, which probably will be this week. Thanks for your patience!
@are : Thanks for this.Keep me posted on this.After checking with new version will close this issue okay ?