Realtime Database Listener Crashes on Internet Disconnection
還沒有人認領這個 Issue。
評估
- 難度
- 5/5
- 預估耗時
- 一週以上
- 新手友好度
- 25/100
研究方向
從報告中所示的 DatabaseListener.start_listener 方法和 Firebase Realtime Database 的 ref.listen 呼叫開始。在 listener 處於作用中時中斷網際網路連線,以重現故障,並找出哪個 Exception 逸出了目前的處理邏輯。完成的標準是 listener 不會當機,並在連線恢復後繼續執行,同時為回報的故障提供 coverage。
由索引模型根據 Issue 內容生成。
描述
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
- 主要語言
- Python
- 星號
- 1.2k
- 分支
- 359
- 平均合併
- 5 天 6 分鐘
- 30 天內合併 PR
- 2
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
firebase/firebase-admin-python 的其他 Issue
-
api: remoteconfig
難度 2/5 1-3 小時 新手友好度 75/100
firebase/firebase-admin-python#957 · 1 則留言 ·
-
api: database type: feature request
難度 2/5 1-3 小時 新手友好度 62/100
-
難度 4/5 3-5 天 新手友好度 45/100
firebase/firebase-admin-python#978 · 1 則留言 ·
-
[FR] Support VERIFY_AND_CHANGE_EMAIL in generate_email_action_link (parity with firebase-admin-node) 未關閉api: auth
firebase/firebase-admin-python#949 · 2 則留言 · 1 個 reaction · 已指派 1 人 ·
-
難度 4/5 3-5 天 新手友好度 43/100
firebase/firebase-admin-python#945 · 1 則留言 · 1 個 reaction ·
查看 firebase/firebase-admin-python 的全部 Issue
相似的 Issue
-
bug ci good first issue
難度 2/5 1-3 小時 新手友好度 88/100
-
難度 2/5 1-3 小時 新手友好度 76/100
-
documentation
難度 2/5 半天 新手友好度 62/100
inmanta/inmanta-core#10835 ·
-
難度 1/5 1 小時以內 新手友好度 92/100
-
sponsored
難度 2/5 1-3 小時 新手友好度 65/100