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

Đang mở Phù hợp với người mới
#1,775 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 5 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
76/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
mysql, postgresql, python
Lĩnh vực
backend, database

Hướng nghiên cứu

Bắt đầu với Connection.ping() trong src/datajoint/connection.py và kiểm tra các phương thức ping() của bộ điều hợp MySQL và PostgreSQL. Kiểm tra cách is_connected xử lý lỗi ping và tìm các bài kiểm thử kết nối hiện có để mở rộng; issue không nêu tên tệp kiểm thử nào. Công việc hoàn tất khi kết nối đã ngắt khiến ping() phát sinh ngoại lệ và is_connected trả về False, bao gồm cả trường hợp PostgreSQL.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.
Ngôn ngữ chính
Python
Star
198
Fork
107
Merge trung bình
4 ngày 7 giờ
Pull request đã merge (30 ngày)
12

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của datajoint/datajoint-python

Tất cả issue của datajoint/datajoint-python

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.