title: How to fix Firestore 'Could not reach Cloud Firestore backend' and Firestore not syncing?
body: <p>Sporadically my Flutter App doesn't connect to Firestore throwing the following error:</p>
  
  <pre><code>6.4.0 - [Firebase/Firestore][I-FST000001] Could not reach Cloud Firestore backend. Connection failed 1 times. Most recent error: An internal error has occurred, print and inspect the error details for more information.
   This typically indicates that your device does not have a healthy Internet connection at the moment. The client will operate in offline mode until it is able to successfully connect to the backend.
  </code></pre>
  
  <p>This error is not because of lacking internet connection, because everything else is connecting to WiFi fine. My app won't connect at all when this happens, despite WiFi, even when waiting longer.</p>
  
  <p>I've found out that the error disappears when I clear the simulators cache and erase all data or when I log out and back into the app with Firebase Auth, with the method from FirebaseAuth 'signInWithEmailAndPassword()'. 
  Then all of my App syncs with Firestore correctly.</p>
  
  <p>Also, after the first error, there are constantly messages such as the following showing up, every 5 seconds or so, until my debug console is filled with them:</p>
  
  <pre><code>[C3.1 96DABBD1-6CC6-4E9A-B011-C5EBC32D0E23 127.0.0.1:64613&lt;-&gt;216.58.213.234:443]
      Connected Path: satisfied (Path is satisfied), interface: en0
      Duration: 0.312s, DNS @0.000s took 0.003s, TCP @0.005s took 0.032s, TLS took 0.100s
      bytes in/out: 4846/1139, packets in/out: 7/9, rtt: 0.001s, retransmitted packets: 0, out-of-order packets: 0
      [C4.1 D7B033A7-E01B-4955-A1D4-F77FD131D1E7 127.0.0.1:64615&lt;-&gt;216.58.213.234:443]
      Connected Path: satisfied (Path is satisfied), interface: en0
      Duration: 0.341s, DNS @0.000s took 0.002s, TCP @0.004s took 0.035s, TLS took 0.136s
      bytes in/out: 5205/1139, packets in/out: 8/9, rtt: 0.001s, retransmitted packets: 0, out-of-order packets: 0
      [C5.1 6C246F61-0CE5-41B2-96A7-5899459A8CDF 127.0.0.1:64617&lt;-&gt;172.217.16.74:443]
      Connected Path: satisfied (Path is satisfied), interface: en0
      Duration: 0.341s, DNS @0.000s took 0.003s, TCP @0.004s took 0.031s, TLS took 0.094s
      bytes in/out: 5039/1139, packets in/out: 5/9, rtt: 0.001s, retransmitted packets: 0, out-of-order packets: 0
      [C6.1 B79FD00C-7B4A-46D4-97D5-A1437FD4065B 127.0.0.1:64619&lt;-&gt;172.217.16.74:443]
      Connected Path: satisfied (Path is satisfied), interface: en0
      Duration: 0.331s, DNS @0.000s took 0.004s, TCP @0.006s took 0.031s, TLS took 0.101s
      bytes in/out: 5088/1139, packets in/out: 6/9, rtt: 0.001s, retransmitted packets: 0, out-of-order packets: 0
      [C7.1 FC9A9A87-24F8-4B67-903D-48C20CF85EDC 127.0.0.1:64623&lt;-&gt;172.217.16.74:443]
      Connected Path: satisfied (Path is satisfied), interface: en0
      Duration: 0.468s, DNS @0.000s took 0.002s, TCP @0.004s took 0.066s, TLS took 0.101s
      bytes in/out: 5246/1139, packets in/out: 6/9, rtt: 0.002s, retransmitted packets: 0, out-of-order packets: 0
      [C8.1 9525CA5F-DD20-4293-89B8-1590FBA8BB3A 127.0.0.1:64627&lt;-&gt;172.217.19.74:443]
      Connected Path: satisfied (Path is satisfied), interface: en0
      Duration: 0.346s, DNS @0.000s took 0.003s, TCP @0.005s took 0.032s, TLS took 0.105s
      bytes in/out: 5203/1093, packets in/out: 7/8, rtt: 0.001s, retransmitted packets: 0, out-of-order packets: 0
      [C9.1 7373F792-2C38-4583-9CD7-488D270B38FF 127.0.0.1:64631&lt;-&gt;172.217.19.74:443]
      Connected Path: satisfied (Path is satisfied), interface: en0
      Duration: 0.311s, DNS @0.000s took 0.002s, TCP @0.004s took 0.031s, TLS took 0.103s
      bytes in/out: 4882/1139, packets in/out: 5/9, rtt: 0.001s, retransmitted packets: 0, out-of-order packets: 0
      [C10.1 A4CA01D7-F8DD-48D6-8F6B-0A7F1B1BE81D 127.0.0.1:64635&lt;-&gt;172.217.19.74:443]
      Connected Path: satisfied (Path is satisfied), interface: en0
      Duration: 0.318s, DNS @0.003s took 0.007s, TCP @0.014s took 0.033s, TLS took 0.109s
      bytes in/out: 5110/1139, packets in/out: 7/9, rtt: 0.001s, retransmitted packets: 0, out-of-order packets: 0
      [C11.1 DA879EBE-02BF-4FD4-A63B-708DCD505ED9 127.0.0.1:64637&lt;-&gt;172.217.19.74:443]
      Connected Path: satisfied (Path is satisfied), interface: en0
      Duration: 1.032s, DNS @0.000s took 0.002s, TCP @0.004s took 0.031s, TLS took 0.158s
      bytes in/out: 4803/1139, packets in/out: 5/9, rtt: 0.001s, retransmitted packets: 0, out-of-order packets: 0
      [C12.1 B8C5396A-2168-491E-80C9-3681925B6669 127.0.0.1:64641&lt;-&gt;172.217.19.74:443]
  </code></pre>
  
  <p>Once this error has occurred, despite rebooting the app from cold, I can't sync with Firestore and all writes occur only locally and no new data from the server is added locally.</p>
  
  <p>Since it works after logging out and back in, I have included the relevant authentication code. I have not found a problem, but maybe there is something wrong with it that is causing the error:</p>
  
  <p>This method is run on every start of the application.</p>
  
  <pre><code>void checkLoginstatusAndNavigate() {
      auth.getUser.then(
        (user) {
          if (user != null) {
  
            Navigator.pushReplacementNamed(context, '/home');
          } else {
            Navigator.pushReplacementNamed(context, '/start');
          }
        },
      ).catchError((error) {
        print(error);
        Navigator.pushReplacementNamed(context, '/start');
      });
    }
  </code></pre>
  
  <p>At the top of my App is a StreamProvider that provides a Stream of FirebaseUser, maybe this is relevant too. </p>
  
  <p>Also, I'm not using any VPN and my AntiVirus is turned off.</p>
  
  <p>I would be very grateful for any kind of insight or help, since this is an error that I've been trying to fix for all of the last week without any results :(.</p>
  
  <p>Thank you!</p>