How to fix database/network-error in Firebase

FirebaseINTERMEDIATEMEDIUMUpdated Dec 22, 2025· 199 views

Firebase Realtime Database network errors occur when your app loses connectivity to Firebase servers due to network timeouts, interrupted connections, or unreachable hosts. Reconnect by checking network status, validating authentication tokens, and implementing proper error handling with exponential backoff.

Quick fix

Fixes database/network-error

1. Visit https://status.firebase.google.com/
  1. Verify basic network connectivity
  2. Check Firebase status and services
  3. Implement proper network error handling in your code
  4. Verify Firebase Realtime Database URL configuration
firebase — error
1. Visit https://status.firebase.google.com/
database/network-error

What this error means

The "database/network-error" occurs when your Firebase Realtime Database client cannot establish or maintain a connection to Google's Firebase servers. This typically happens when the client experiences a timeout, has an interrupted connection, or cannot reach the Firebase host. Unlike a local network problem you can diagnose, this error is thrown by Firebase's SDK when its internal network communication fails. The error can be transient (temporary network hiccup) or persistent (underlying connectivity issue), and your app should be designed to handle both gracefully by implementing reconnection logic.

Typical symptoms

  • Real-time listener callbacks never fire or stop firing after a period of time
  • Database read/write operations fail with a network error code
  • App works on some networks (mobile data) but fails on others (WiFi)
  • Connection fails after the app goes to the background and returns to the foreground
  • Device goes to sleep and fails to reconnect when waking up
  • Error persists for hours or days despite good network connectivity
  • Console shows "WebSocket error. Closing connection" messages

Common causes

  1. Network connectivity loss or poor signal strength on device or WiFi
  2. Firebase authentication token expired while offline and not refreshed on reconnection
  3. Firewall or corporate proxy blocking WebSocket connections to Firebase servers
  4. Device sleep/wake cycle causing SDK to fail reconnecting to the database
  5. App backgrounding causing WebSocket connection to be forcefully closed by OS
  6. Router misconfiguration or ISP blocking Google IP addresses
  7. Firebase Realtime Database service experiencing an outage
  8. Client timeout before server responds due to slow network

How to fix "database/network-error"

1Verify basic network connectivity

First, confirm your device has internet access. Open a web browser and navigate to https://www.google.com or another website. If you cannot access any websites:

1. Check WiFi or mobile signal strength
2. Try switching networks (WiFi to mobile data or vice versa)
3. Restart your device's network interface
4. Restart your router if on WiFi

If basic connectivity works but Firebase still fails, continue to the next steps.

2Check Firebase status and services

Verify that Firebase services are not experiencing an outage:

javascript
1. Visit https://status.firebase.google.com/

2. Check for any incidents affecting "Realtime Database" in your region
3. If an outage is reported, wait for Google to resolve it
4. If no outage is shown but you still have issues, continue troubleshooting

Occasionally, specific networks (like certain ISPs) may temporarily lose access to Firebase servers.

3Implement proper network error handling in your code

Add a listener for Firebase connection state and handle errors gracefully:

javascript
// Web SDK
const connectedRef = firebase.database().ref(".info/connected");
connectedRef.on("value", (snap) => {
  if (snap.val() === true) {
    console.log("Connected to Firebase");
  } else {
    console.log("Disconnected from Firebase");
  }
});

// Monitor database errors
const db = firebase.database();
db.ref("your/path").on("value", 
  (snapshot) => {
    console.log("Data:", snapshot.val());
  },
  (error) => {
    if (error.code === "NETWORK_ERROR") {
      console.log("Network error, will retry automatically");
    } else {
      console.error("Database error:", error.code, error.message);
    }
  }
);
kotlin
// Android SDK
val database = FirebaseDatabase.getInstance()
val ref = database.getReference("your/path")

ref.addValueEventListener(object : ValueEventListener {
  override fun onDataChange(snapshot: DataSnapshot) {
    // Handle data
  }
  
  override fun onCancelled(error: DatabaseError) {
    when (error.code) {
      DatabaseError.NETWORK_ERROR -> {
        Log.e("Firebase", "Network error: " + error.message)
        // Implement retry logic with exponential backoff
      }
      else -> Log.e("Firebase", "Database error: " + error.message)
    }
  }
})

Firebase SDKs have built-in automatic retry logic, but you should acknowledge network errors in your UI so users understand what's happening.

4Verify Firebase Realtime Database URL configuration

Ensure your Firebase Database URL is correctly configured in your app:

javascript
// Web SDK
const firebaseConfig = {
  apiKey: "YOUR_API_KEY",
  authDomain: "YOUR_PROJECT.firebaseapp.com",
  databaseURL: "https://YOUR_PROJECT.firebaseio.com", // Make sure this is correct
  projectId: "YOUR_PROJECT",
  // ...
};

const app = initializeApp(firebaseConfig);
const db = getDatabase(app);
kotlin
// Android - typically configured in google-services.json
// Verify your google-services.json is from the correct Firebase project

1. Go to Firebase Console → Project Settings → Your App
2. Confirm the Database URL matches your Realtime Database instance URL
3. The URL should be in format: https://YOUR_PROJECT.firebaseio.com
4. If incorrect, update your config and redeploy

5Check Firebase security rules and authentication

Network errors can sometimes mask authentication failures:

javascript
// Verify user is authenticated
const auth = getAuth();
onAuthStateChanged(auth, (user) => {
  if (user) {
    console.log("Authenticated as:", user.uid);
    // Now safe to access database
  } else {
    console.log("Not authenticated");
  }
});

// Check Realtime Database rules
const db = getDatabase();
const ref = ref(db, "test_read");
get(ref).then((snapshot) => {
  if (snapshot.exists()) {
    console.log("Rules allow read access");
  }
}).catch((error) => {
  console.error(error.code, error.message);
});

1. Go to Firebase Console → Realtime Database → Rules
2. Ensure rules allow your authenticated user to access the paths they're reading/writing
3. During development, you can use: {".read": true, ".write": true} (not for production)
4. If rules deny access, it may show as a network error rather than a permission error

6Clear app data and retry (for mobile apps)

Sometimes cached authentication tokens or connection state become corrupted:

1. iOS: Settings → Apps → Your App → Storage → Clear App Data
2. Android: Settings → Apps → Your App → Storage → Clear Cache / Clear Data
3. Web: Open developer tools → Application → Clear Site Data
4. Restart the app and try again

This forces the SDK to reinitialize and obtain fresh authentication tokens.

7Test with a different network if possible

To isolate whether the issue is network-specific:

1. If currently on WiFi, switch to mobile data (or vice versa)
2. Try a different WiFi network (coffee shop, library, another location)
3. If using corporate WiFi, try personal network
4. Test from a different device on the same network

If it works on one network but not another, the issue is network/firewall-specific:
- Contact your network administrator if on corporate WiFi
- Request that *.firebaseio.com and related Firebase domains are whitelisted
- Check for VPN conflicts (try disabling temporarily for testing)

Advanced notes

Firebase SDK Reconnection Behavior: Firebase SDKs implement automatic exponential backoff reconnection, so transient network errors typically resolve within seconds to minutes without intervention. However, if reconnection fails after ~1 hour offline, the authentication token may expire. On some Android devices, the WebSocket connection is forcefully closed when the app enters the background, and the OS may not immediately notify Firebase when connectivity resumes. Implementing your own network state listener (using ConnectivityManager on Android or Reachability on iOS) and manually triggering reconnection attempts can improve reliability. For production apps, consider implementing a local persistence strategy (Firebase offline persistence) to serve cached data while offline, then sync when reconnected. On Windows/desktop, ensure Windows Firewall is not blocking WebSocket connections to Firebase. Some corporate proxies intercept HTTPS and WebSocket traffic; contact your network team to allow direct connections to Firebase services.

Frequently asked questions

What does "database/network-error" mean?
The "database/network-error" occurs when your Firebase Realtime Database client cannot establish or maintain a connection to Google's Firebase servers. This typically happens when the client experiences a timeout, has an interrupted connection, or cannot reach the Firebase host. Unlike a local network problem you can diagnose, this error is thrown by Firebase's SDK when its internal network communication fails.
How do I fix "database/network-error"?
Firebase Realtime Database network errors occur when your app loses connectivity to Firebase servers due to network timeouts, interrupted connections, or unreachable hosts. Reconnect by checking network status, validating authentication tokens, and implementing proper error handling with exponential backoff.
What causes "database/network-error"?
Network connectivity loss or poor signal strength on device or WiFi Firebase authentication token expired while offline and not refreshed on reconnection Firewall or corporate proxy blocking WebSocket connections to Firebase servers
Is the "database/network-error" error serious?
It is a medium-severity error — more of a blocker than a risk. The steps above resolve it.

Official resources & further reading