Realtime Database Listener Crashes on Internet Disconnection
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 25/100
Research direction
Start with the DatabaseListener.start_listener method and the Firebase Realtime Database ref.listen call shown in the report. Reproduce the failure by disconnecting the internet while a listener is active, and identify which exception escapes the current handling. Done means the listener does not crash and resumes after connectivity returns, with coverage for the reported failure.
Written by the indexing model from the issue text.
Description
Description
When the internet disconnects, the Firebase Realtime Database listener crashes, even with try and except statements. The application fails to recover and reconnect the listeners, resulting in the following error:
javascript
Code kopieren
google.api_core.exceptions.RetryError: Deadline of 120.0s exceeded while calling target function, last exception: HTTPSConnectionPool(host='storage.googleapis.com', port=443): Max retries exceeded with url: /storage/v1/b/villaduniatest.appspot.com/o?projection=noAcl&prefix=pdfstable%2F&prettyPrint=false (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x0000017C6BBE79D0>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed'))
Reconnecting...
Steps to Reproduce
Start a Firebase Realtime Database listener in a Python application.
Disconnect the internet.
Observe the application crash with the above error.
Expected Behavior
The application should handle the disconnection gracefully, retrying the connection until the internet is restored, without crashing.
Actual Behavior
The application crashes immediately upon internet disconnection, and does not recover.
Environment
Firebase Admin SDK: Python
Python Version: (your Python version)
Operating System: (your OS version)
Additional Context
Here is the relevant portion of the code:
python
Code kopieren
import firebase_admin
from firebase_admin import credentials, initialize_app, db
from requests.exceptions import ConnectionError, Timeout
import time
class DatabaseListener:
def init(self, app_instance):
self.app_instance = app_instance
self.listeners = {}
def start_listener(self, path, callback):
ref = db.reference(path, app=self.app_instance)
while True:
try:
listener = ref.listen(callback)
self.listeners[path] = listener
print(f"Listener started for path: {path}")
break
except (ConnectionError, Timeout) as e:
print(f"Connection error starting listener for {path}: {e}")
time.sleep(5) # Retry after a delay
def stop_listener(self, path):
if path in self.listeners:
listener = self.listeners[path]
listener.close()
del self.listeners[path]
print(f"Listener stopped for path: {path}")
def stop_all_listeners(self):
for path in list(self.listeners.keys()):
self.stop_listener(path)
print("All listeners stopped.")
Any guidance or solutions to ensure the listener can recover from network disconnections would be greatly appreciated
- Dominant language
- Python
- Stars
- 1.2k
- Forks
- 359
- Avg merge
- 5d 6m
- Merged PRs (30d)
- 2
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from firebase/firebase-admin-python
-
api: remoteconfig
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
firebase/firebase-admin-python#957 · 1 comment ·
-
api: database type: feature request
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
-
Difficulty 4/5 3-5 days Newbie friendliness 45/100
firebase/firebase-admin-python#978 · 1 comment ·
-
[FR] Support VERIFY_AND_CHANGE_EMAIL in generate_email_action_link (parity with firebase-admin-node) Openapi: auth
firebase/firebase-admin-python#949 · 2 comments · 1 reaction · 1 assignee ·
-
Difficulty 4/5 3-5 days Newbie friendliness 43/100
firebase/firebase-admin-python#945 · 1 comment · 1 reaction ·
All issues in firebase/firebase-admin-python
Similar issues
-
bug ci good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
documentation
Difficulty 2/5 Half a day Newbie friendliness 62/100
inmanta/inmanta-core#10835 ·
-
sponsored
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
Diaoul/subliminal#1382 ·