Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Failed to get document because the client is offline

I'm using Flutter for a mobile app and have been noticing a intermittent bug recently that makes it so that reading documents from cloud firestore fails. I finally got one of my devices to get the bug so I plugged it in to get logs and I got this error when I tried accessing one of the documents.

flutter : [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: PlatformException(Error performing get, Failed to get document because the client is offline., null)

This error is thrown from this line of my code, which works for 99.9% of users 99.9% of the time

DocumentSnapshot userLivestream = await Firestore.instance.collection('livestreams').document(userId).get();

I've done a lot of reading up on the topic and got a lot of mixed answers. One stack overflow post said it was fixed like 2.5 years ago(obviously not, ref: Firebase Cloud Firestore throws "client is offline"), and others said it was android specific (ref: https://github.com/EddyVerbruggen/nativescript-plugin-firebase/issues/631), but I am experiencing the same issue on both android and iOS. This problem has gotten worse recently, so maybe it is something with the package I am using. The relevant packages here are pasted from my pubspec.yaml.

  firebase_core: ^0.4.0+1
  cloud_firestore: ^0.11.0+1
  firebase_auth: ^0.11.1

sometimes the bug fixes itself after a while, it might have something to do with logging into the app or changing the network the device is connected to, but with that information I still can't consistently replicate the issue. Has anyone run into a similar issue and how did you fix it?

stack trace:

03-31 13:20:09.488 19623  6084 E flutter : [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: PlatformException(Error performing get, Failed to get document because the client is offline., null)
03-31 13:20:09.488 19623  6084 E flutter : #0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:569)
03-31 13:20:09.488 19623  6084 E flutter : #1      MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:321)
03-31 13:20:09.488 19623  6084 E flutter : <asynchronous suspension>
03-31 13:20:09.488 19623  6084 E flutter : #2      MethodChannel.invokeMapMethod (package:flutter/src/services/platform_channel.dart:349)
03-31 13:20:09.488 19623  6084 E flutter : #3      DocumentReference.get (package:cloud_firestore/src/document_reference.dart:76)
03-31 13:20:09.488 19623  6084 E flutter : #4      LivestreamRepository.getUsersLivestream (package:hallo/repositories/livestream_repository.dart:81)
03-31 13:20:09.488 19623  6084 E flutter : #5      joinLivestream (package:hallo/presentation/widgets/livestream_previews.dart:448)
03-31 13:20:09.488 19623  6084 E flutter : #6      _AsyncAwaitCompleter.start (dart:async-patch/async_patch.dart:45)
03-31 13:20:09.488 19623  6084 E flutter : #7      joinLivestream (package:hallo/presentation/widgets/livestream_previews.dart:447)
03-31 13:20:09.488 19623  6084 E flutter : #8      LiveStreamMenuState._buildLivestreamList.<anonymous closure>.<anonymous closure> (package:hallo/livestream/livestream_screen.dart:463)
03-31 13:20:09.488 19623  6084 E flutter : #9      _AsyncAwaitCompleter.start (dart:async-patch/async_patch.dart:45)
03-31 13:20:09.488 19623  6084 E flutter : #10     LiveStreamMenuState._buildLivestreamList.<anonymous closure>.<anonymous closure> (package:hallo/livestream/livestream_screen.dart:460)
03-31 13:20:09.488 19623  6084 E flutter : #11     GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:182)
03-31 13:20:09.488 19623  6084 E flutter : #12     TapGestureRecognizer.handleTapUp (package:flutter/src/gestures/tap.dart:486)
03-31 13:20:09.488 19623  6084 E flutter : #13     BaseTapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:282)
03-31 13:20:09.488 19623  6084 E flutter : #14     BaseTapGestureRecognizer.acceptGesture (package:flutter/src/gestures/tap.dart:236)
03-31 13:20:09.488 19623  6084 E flutter : #15     GestureArenaManager.sweep (package:flutter/src/gestures/arena.dart:156)
03-31 13:20:09.488 19623  6084 E flutter : #16     GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:222)
03-31 13:20:09.488 19623  6084 E flutter : #17     GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:198)
03-31 13:20:09.488 19623  6084 E flutter : #18     GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:156)
03-31 13:20:09.488 19623  6084 E flutter : #19     GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:102)
03-31 13:20:09.488 19623  6084 E flutter : #20     GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:86)
03-31 13:20:09.488 19623  6084 E flutter : #21     _rootRunUnary (dart:async/zone.dart:1138)
03-31 13:20:09.488 19623  6084 E flutter : #22     _CustomZone.runUnary (dart:async/zone.dart:1031)
03-31 13:20:09.488 19623  6084 E flutter : #23     _CustomZone.runUnaryGuarded (dart:async/zone.dart:933)
03-31 13:20:09.488 19623  6084 E flutter : #24     _invoke1 (dart:ui/hooks.dart:273)
03-31 13:20:09.488 19623  6084 E flutter : #25     _dispatchPointerDataPacket (dart:ui/hooks.dart:182)
like image 810
Dean Packard Avatar asked Mar 31 '20 22:03

Dean Packard


1 Answers

I faced the same issue. I tried to reference the collection which is not yet created. So, I just created a collection with dummy doc. And now it's working good.

The cloud_firestore developers should have to take concern on error reports.

like image 141
DJ Hemath Avatar answered Nov 09 '22 06:11

DJ Hemath