Realtime Database Listener Crashes on Internet Disconnection

未關閉
#791 2 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

評估

難度
5/5
預估耗時
一週以上
新手友好度
25/100
Issue 類型
缺陷
描述清晰度
需要釐清
活躍度
停滯
技術堆疊
firebase, python
領域
backend, databases

研究方向

從報告中所示的 DatabaseListener.start_listener 方法和 Firebase Realtime Database 的 ref.listen 呼叫開始。在 listener 處於作用中時中斷網際網路連線,以重現故障,並找出哪個 Exception 逸出了目前的處理邏輯。完成的標準是 listener 不會當機,並在連線恢復後繼續執行,同時為回報的故障提供 coverage。

由索引模型根據 Issue 內容生成。

描述

api: database

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

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

firebase/firebase-admin-python 的其他 Issue

查看 firebase/firebase-admin-python 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。