is_connected and ping() report a dead connection as live (since 2.1.0)

オープン 初心者向け
#1,775 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 5 日以内に返信

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

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
76/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
mysql, postgresql, python
領域
backend, database

調査の方向性

src/datajoint/connection.py の Connection.ping() から始め、MySQL および PostgreSQL アダプターの ping() メソッドを調べてください。is_connected が ping の失敗をどのように処理するかを確認し、拡張できる既存の接続テストを探してください。issue にはテストファイルの指定がありません。切断された接続によって ping() が例外を発生させ、is_connected が False を返すこと(PostgreSQL の場合も含む)を完了条件とします。

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

説明

bug triage

Bug Report

Description

Connection.ping() no longer raises when the connection is dead, so Connection.is_connected stays True after the server kills the connection or stops. It only turns False after close(). We check is_connected in a health endpoint, and it reported a stopped server as connected.

Connection.ping() calls self.adapter.ping(self._conn) and discards the result. MySQLAdapter.ping() catches every exception and returns False, so ping() never raises, and is_connected never reaches its except branch.

Reproducibility

Include:

  • OS: Linux (Ubuntu on WSL2)
  • Python 3.12.13
  • MySQL 8.4.11
  • local-docker
  • DataJoint 2.3.6 (the code is unchanged on master)
Steps:
import datajoint as dj
import pymysql

conn = dj.conn()
config = dj.config
admin = pymysql.connect(host=config['database.host'], port=config['database.port'],
                        user=config['database.user'], password=config['database.password'])
with admin.cursor() as cursor:
    cursor.execute(f'KILL {conn.connection_id}')

print(conn.adapter.ping(conn._conn))  # False
print(conn.is_connected)              # True
conn.ping()                           # does not raise
print(conn)                           # DataJoint connection (connected) root@...
Expected Behavior

ping() raises and is_connected returns False once the server has dropped the connection, as in 0.14.4 and 2.0.0, where ping() called self._conn.ping(reconnect=False) directly.

Additional Research and Context
  • Introduced in 2.1.0, when ping() started going through the backend adapters.
  • Connection.ping() ignores the adapter's result: https://github.com/datajoint/datajoint-python/blob/v2.3.6/src/datajoint/connection.py#L392-L401
  • The adapters return False instead of raising: MySQL, PostgreSQL (the PostgreSQL case is not tested).
  • repr (L251) and in_transaction (L531) read is_connected, so they are wrong in the same way.
  • #1734 relies on is_connected noticing a dead connection ("Closed by close(), or found dead by is_connected").
  • Possible fix: in Connection.ping(), raise errors.LostConnectionError when self.adapter.ping(self._conn) returns False.
主要言語
Python
スター
198
フォーク
107
平均マージ
4日 7時間
マージ済み PR(30日)
12

環境構築

はじめの一歩

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

datajoint/datajoint-python のほかの issue

datajoint/datajoint-python の issue をすべて見る

似ている issue

Python の issue をもっと見る

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

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