Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Firebase db listener cannot handle with internet disconnetions

オープン
#287 コメント 13 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
説明が足りない
活発さ
停滞
技術スタック
firebase, python

調査の方向性

まず、issue に示されている SSEClient クラスと Event クラスを調べ、次に db.reference().listen() の実行中または実行後にネットワークを切断して失敗を再現します。listener がストリームの中断と再接続をどのように処理するかを追跡します。完了条件は、listener が Firebase の更新の受信を再開し、listen() の後のコードが無期限にブロックされないことです。

索引モデルが issue の本文から書いたものです。

説明

api: database
[READ] Step 1: Are you in the right place?
  • For issues or feature requests related to the code in this repository
    file a Github issue.
    • If this is a feature request make sure the issue title starts with "FR:".
  • For general technical questions, post a question on StackOverflow
    with the firebase tag.
  • For general Firebase discussion, use the firebase-talk
    google group.
  • For help troubleshooting your application that does not fall under one
    of the above categories, reach out to the personalized
    Firebase support channel.
[REQUIRED] Step 2: Describe your environment
  • Operating System version: Ubuntu 18 and Raspbian
  • Firebase SDK version: lasted realesed with pip install
  • Library version: lasted realesed with pip install
  • Firebase Product: firebase db stream (listener)
[REQUIRED] Step 3: Describe the problem

db.reference().listen() hang all code, do not run the rest of code, if when during connection of listener get internet disconnected, or if streamming allready connected and get disconnected for more than 2~3min and reconnect, do not get any updates from firebase.
i was searching for the root of this problem, and realised SSEclient have timeout default set by 3000, and the Event class retry time is set by None. Im not sure about this but maybe this is the problem?

Steps to reproduce:

To simulate the error we can just pull the cable or simply disconnect the internet from the system, wait 2 minutes to 3 minutes to reconnect it, after the reconnection, update any end-point that the streamming is listening. We can notice that we will not receive any updates.

It is also possible to simulate it during the streaming connection opening disconnect the internet and wait 2 to 3 minutes again and reconnect. We will not receive any updates from the firebase, and it will also be noticed that when this occurs, the codes below the opening stream do not run even wait for long time.

Relevant Code:

class SSEClient(object):
'''SSE client implementation.'''

def __init__(self, url, session, retry=3000, **kwargs):
    """Initializes the SSEClient.
    Args:
      url: The remote url to connect to.
      session: The requests session.
      retry: The retry interval in milliseconds (optional).
      **kwargs: Extra kwargs that will be sent to ``requests.get()`` (optional).
    """

class Event(object):
'''Event represents the events fired by SSE.'''

sse_line_pattern = re.compile('(?P<name>[^:]*):?( ?(?P<value>.*))?')

def __init__(self, data='', event_type='message', event_id=None, retry=None):
    self.data = data
    self.event_type = event_type
    self.event_id = event_id
    self.retry = retry

// TODO(you): code here to reproduce the problem

import firebase_admin
from firebase_admin import db
from firebase_admin import credentials

# Init Firebase.
dir_path = os.path.dirname(os.path.realpath(__file__))
cred = credentials.Certificate(dir_path + '/serviceAccountKey.json')
firebase_admin.initialize_app(cred, {
    'databaseURL': DB_URL
})

try:
    streaming = db.reference('path').listen(callback)
except ApiCallError:
    timer = 0

# did this code above to handle with disconnections.
timer = 100
while True:
    if internet_on():
        if timer == 0:
            try:
                streaming.close()
           except:
                #we do not have streaming connections open.
                pass
            try:
                streaming = db.reference('path').listen(callback)
                timer = 100
            except ApiCallError:
                timer = 0
    else:
        time.sleep(1)
        timer -= 1 if timer > 0 else 0
主要言語
Python
スター
1.2k
フォーク
359
平均マージ
3日 9時間
マージ済み PR(30日)
3

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

firebase/firebase-admin-python のほかの issue

firebase/firebase-admin-python の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。