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

Offen Anfängerfreundlich
#1,775 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 5 Tagen

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Anfängerfreundlichkeit
76/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
mysql, postgresql, python
Bereich
backend, database

Rechercherichtung

Beginne mit Connection.ping() in src/datajoint/connection.py und untersuche die ping()-Methoden der MySQL- und PostgreSQL-Adapter. Prüfe, wie is_connected mit fehlgeschlagenen Pings umgeht, und suche nach vorhandenen Verbindungstests, die erweitert werden können; im Issue wird keine Testdatei genannt. Fertig ist die Arbeit, wenn eine tote Verbindung dazu führt, dass ping() eine Ausnahme auslöst und is_connected False zurückgibt, auch im PostgreSQL-Fall.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

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.
Vorherrschende Sprache
Python
Sterne
198
Forks
107
Ø Merge
4 T. 7 Std.
Gemergte PRs (30 T.)
12

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus datajoint/datajoint-python

Alle Issues in datajoint/datajoint-python

Ähnliche Issues

Weitere Issues zu Python

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.