SQLite: Basic Auth login fails with 'database is locked' (503) - token invalidation reads before writing inside a deferred transaction, busy_timeout cannot apply

Đang mở
#66,627 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 1 ngày

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

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
45/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ệ
php, sqlite
Lĩnh vực
authentication, database

Hướng nghiên cứu

Start at OC\User\Session::createSessionToken, where atomic() wraps invalidateToken and generateToken, then follow PublicKeyTokenProvider::invalidateToken into PublicKeyTokenMapper::invalidate and the preceding getToken read. Read how Doctrine transactions and retries are handled around this call, and look for existing RetryableException retry patterns in the codebase. Reproduce with two SQLite connections, one writing and one doing Basic Auth login; done means the login no longer returns 503 under concurrent writes and the auth-token tests still pass.

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

Mô tả

Bug description

On SQLite instances (journal_mode WAL, the default), a request with Basic Auth (WebDAV, OCS, login) can fail hard with 500/503 when another connection writes concurrently. Observed on 33.0.x and 35.0.3 (CI, PHP 8.3), identical stack on both:

SQLSTATE[HY000]: General error: 5 database is locked
PublicKeyTokenMapper::invalidate (DELETE FROM oc_authtoken)
<- PublicKeyTokenProvider::invalidateToken
<- OC\User\Session::createSessionToken (TTransactional::atomic)
<- OCA\DAV\Connector\Sabre\Auth::validateUserPass -> Sabre ServiceUnavailable (503)

Analysis: createSessionToken wraps invalidateToken + generateToken in atomic(), which opens a deferred transaction. invalidateToken first SELECTs the token (mapper->getToken) and then DELETEs it. In WAL mode, upgrading a read snapshot to a write fails immediately with SQLITE_BUSY when another connection committed since the snapshot was taken; SQLite does not consult the busy handler in this case, so PDO's default 60 s busy timeout (and any dbdriveroptions timeout) cannot help. The error reached the client within about one second while a concurrent request committed a small UPDATE on an app table.

Steps to reproduce
  1. Nextcloud on SQLite, two clients.
  2. Client A issues short writes in a loop (any app table).
  3. Client B logs in repeatedly with Basic Auth (e.g. WebDAV MKCOL without a session cookie).
  4. Occasionally B receives 503, nextcloud.log shows the stack above.
Expected behavior

The login either waits or retries; a transient SQLite lock should not surface as a failed request. Suggestion: retry the whole atomic() block on Doctrine RetryableException (like other retry-on-lock spots), or avoid the read-before-write by moving mapper->getToken out of the write transaction so the first statement in the transaction is the write.

Environment
  • Nextcloud Server: 35.0.3 (also on 33.0.x)
  • Database: SQLite (journal_mode WAL)
  • PHP: 8.3
  • Install method: CI test instance; the mechanism applies to any SQLite install

Analysis assisted by AI; verified against server source and logs.

Ngôn ngữ chính
PHP
Star
37.6k
Fork
5.4k
Merge trung bình
1 ngày 10 giờ
Pull request đã merge (30 ngày)
625

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

Mở trong Codespaces

Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.

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 nextcloud/server

Tất cả issue của nextcloud/server

Issue tương tự

Thêm issue về PHP

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.