The Firebase "unavailable" error occurs when your application cannot reach the Firebase service backend. This is typically a transient network or service issue that can be resolved with proper error handling, retry logic, and connection verification.
This error indicates that the Firebase service is currently unreachable from your application. The error commonly appears across multiple Firebase services including Cloud Firestore, Realtime Database, Cloud Functions, and Cloud Messaging. When this error occurs, the Firebase SDK cannot establish or maintain a connection to the backend, preventing operations from completing. The error message typically states "The service is currently unavailable. This is a most likely a transient condition and may be corrected by retrying with a backoff." Unlike permission or validation errors, an unavailable error is usually temporary and caused by network connectivity issues, Firebase service interruptions, or device offline status. The SDK will often retry automatically, but implementing your own retry logic with exponential backoff provides better control and user experience.
Before troubleshooting your code, verify that Firebase services are operational.
Visit the Firebase Status Dashboard at https://status.firebase.google.com/ to check for ongoing incidents or maintenance affecting Firebase services. If there is a service outage affecting your region or service type, wait for Firebase to restore serviceโthere is nothing you can do on your client until the backend recovers.
Ensure your device has a working internet connection.
Test your connection:
if (navigator.onLine) {
console.log("Device is online");
} else {
console.log("Device is offline");
}If offline, connect to a working network. If still failing after connecting:
- Try switching from WiFi to cellular or to a different network
- Disable VPN or corporate proxy temporarily to test
- Check if your firewall blocks Firebase endpoints (*.firebase.io, *.firebaseio.com)
- Test on a different device or network to isolate the issue
The unavailable error often occurs when you call Firebase APIs before the SDK finishes initializing.
import { initializeApp } from "firebase/app";
import { getFirestore } from "firebase/firestore";
const firebaseConfig = {
apiKey: process.env.REACT_APP_FIREBASE_API_KEY,
authDomain: process.env.REACT_APP_FIREBASE_AUTH_DOMAIN,
projectId: process.env.REACT_APP_FIREBASE_PROJECT_ID,
storageBucket: process.env.REACT_APP_FIREBASE_STORAGE_BUCKET,
messagingSenderId: process.env.REACT_APP_FIREBASE_MESSAGING_SENDER_ID,
appId: process.env.REACT_APP_FIREBASE_APP_ID,
};
const app = initializeApp(firebaseConfig);
const db = getFirestore(app); // Ensure initialization succeeds before using db
// Wait for initialization before querying
await db.ready(); // Some SDKs support this patternMake sure all environment variables are set correctly and the app initializes without errors.
Firebase recommends handling transient unavailability with automatic retry logic using exponential backoff.
async function queryWithRetry(queryFn, maxRetries = 3) {
for (let attempt = 1; attempt <= maxRetries; attempt++) {
try {
return await queryFn();
} catch (error) {
if (error.code === "unavailable" && attempt < maxRetries) {
const delayMs = Math.min(1000 * Math.pow(2, attempt - 1), 10000); // 1s, 2s, 4s max 10s
console.log(`Retry attempt ${attempt} in ${delayMs}ms...`);
await new Promise(r => setTimeout(r, delayMs));
} else {
throw error; // Rethrow after max retries or non-transient error
}
}
}
}
// Usage
const result = await queryWithRetry(async () => {
const snapshot = await getDocs(collection(db, "users"));
return snapshot.docs;
});This approach gives transient issues time to resolve without overwhelming the Firebase backend.
Outdated Firebase SDKs may have connectivity bugs or compatibility issues.
For npm/Node.js:
npm install firebase@latestFor React Native:
npm install @react-native-firebase/firestore@latestFor Flutter:
flutter pub upgrade cloud_firestoreFor Android (native):
Update your build.gradle:
dependencies {
implementation "com.google.firebase:firebase-firestore:35.0.0" // Update to latest
}After upgrading, clear your build cache and restart/rebuild your app.
If your Firestore SDK entered offline mode and never reconnected, explicitly re-enable networking.
import { enableNetwork } from "firebase/firestore";
const db = getFirestore();
// Force reconnection
await enableNetwork(db);
console.log("Network re-enabled");For Realtime Database, disconnect and reconnect:
import { ref, goOffline, goOnline } from "firebase/database";
const db = getDatabase();
goOffline(db);
// Wait a moment, then reconnect
setTimeout(() => {
goOnline(db);
console.log("Database reconnected");
}, 1000);Some Firebase services require authentication. If your auth token expired, the service becomes unavailable.
import { getAuth, onAuthStateChanged } from "firebase/auth";
const auth = getAuth();
onAuthStateChanged(auth, (user) => {
if (user) {
console.log("User authenticated:", user.uid);
// Now safe to use Firestore/other services
} else {
console.log("User not authenticated - Firebase services may be unavailable");
// Sign in or use anonymous auth
}
});
// For anonymous auth:
import { signInAnonymously } from "firebase/auth";
await signInAnonymously(auth);Ensure your user is properly authenticated before making requests to protected services.
Add connection monitoring to detect when Firebase becomes unavailable and gracefully degrade your app.
import { ref, onValue } from "firebase/database";
const db = getDatabase();
const connectedRef = ref(db, ".info/connected");
onValue(connectedRef, (snapshot) => {
if (snapshot.val() === true) {
console.log("Firebase connected");
// Sync data, update UI
} else {
console.log("Firebase unavailable - using cached data");
// Display cached data, disable writes, show offline indicator
}
});For Firestore:
import { enableNetwork, disableNetwork } from "firebase/firestore";
window.addEventListener("online", async () => {
await enableNetwork(db);
console.log("Back online - Firestore re-enabled");
});
window.addEventListener("offline", async () => {
await disableNetwork(db);
console.log("Offline - Firestore disabled");
});Android-Specific Issues: The unavailable error is significantly more frequent on Android than web or iOS. Ensure your device has sufficient memory and network bandwidth. Consider implementing more aggressive retry logic (4-5 attempts) and longer timeouts (15-20 seconds) for Android specifically.
Emulator Issues: When using the Firebase Emulator Suite or Android Emulator, the unavailable error can occur if the emulator cannot reach your development machine's localhost. Ensure localhost:8080 (Firestore emulator) and other emulator ports are accessible from the emulator network.
Regional Deployments: Users in Europe and Asia have reported occasional unavailability with regional databases. If experiencing chronic issues, try selecting US-central1 or checking your Firebase Console for regional availability status.
Rate Limiting: High-frequency requests may trigger rate limiting, causing unavailable errors. Implement request batching and cache-aside patterns to reduce unnecessary queries.
SDK Initialization Race Conditions: Some frameworks (React Native, Flutter) initialize Firebase asynchronously. Ensure you await initialization before making any API calls. Use promise-based patterns rather than synchronous access.
Callable Functions: INTERNAL - Unhandled exception
How to fix "Callable Functions: INTERNAL - Unhandled exception" in Firebase
auth/invalid-hash-algorithm: Hash algorithm doesn't match supported options
How to fix "auth/invalid-hash-algorithm: Hash algorithm doesn't match supported options" in Firebase
Hosting: CORS configuration not set up properly
How to fix CORS configuration in Firebase Hosting
auth/reserved-claims: Custom claims use reserved OIDC claim names
How to fix "reserved claims" error when setting custom claims in Firebase
Callable Functions: UNAUTHENTICATED - Invalid credentials
How to fix "UNAUTHENTICATED - Invalid credentials" in Firebase Callable Functions