Realtime Database Listener Crashes on Internet Disconnection

Abierto
#791 2 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
5/5
Tiempo estimado
Más de una semana
Aptitud para principiantes
25/100
Tipo de issue
Error
Claridad
Necesita aclaración
Estado de actividad
Estancado
Stack tecnológico
firebase, python

Línea de trabajo

Comienza con el método DatabaseListener.start_listener y la llamada ref.listen de Firebase Realtime Database que se muestran en el informe. Reproduce el fallo desconectando Internet mientras hay un listener activo e identifica qué Exception escapa al manejo actual. Se considera completado cuando el listener no se bloquea y se reanuda después de que vuelva la conectividad, con cobertura para el fallo informado.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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

Lenguaje dominante
Python
Estrellas
1.2k
Forks
359
Merge medio
5 d 6 min
PR fusionados (30 d)
2

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de firebase/firebase-admin-python

Todos los issues de firebase/firebase-admin-python

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.