[TECH DEBT] Encapsulate the sign-in state in AsyncAuth

Đang mở
#70,712 0 bình luận 0 reaction 1 người được giao Xem trên GitHub

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

@charzl đang làm issue này rồi.

Từ ngày 6/11/2026.

Đánh giá

Issue này chưa được đánh giá.

Mô tả

tech-debt
Description of the tech debt to be addressed, include links and screenshots

The sign-in state in salt.crypt.AsyncAuth is spread over several places:

  • _authenticate_future is created in authenticate() and __singleton_init__, written by _authenticate(), read by authenticated and authenticate(), and deleted by invalidate(). It does not exist before the first sign-in, so every reader checks hasattr.
  • With #70603 it holds a task instead of a future, and the number of waiters lives in a second attribute, _authenticate_waiters.

This is hard to follow, and it is what #70642 had to untangle: a cancelled shared future, a result set twice, and authenticated raising CancelledError.

Only salt/crypt.py touches the attribute. The rest of the code uses authenticate(), authenticated and invalidate().

Proposed change

Keep the public API. Hold the current sign-in in one small object: the task and its waiter count, with the join, leave and cancel logic inside it. AsyncAuth keeps one attribute that is None until the first sign-in, and authenticated is derived from that object.

Steps, one commit each:

  1. Add tests that pin the current behavior: one cancelled caller does not cancel the others, an error reaches every caller, authenticated is false after a cancelled sign-in, the last caller leaving cancels the sign-in, and invalidate() makes the next call sign in again.
  2. Move the waiter counting and cleanup into the new object.
  3. Replace the uses of _authenticate_future.
  4. Remove the hasattr checks, the del, and _authenticate_waiters.

This should land after #70603, which already gives each caller its own waiter.

Out of scope: invalidate() clearing the shared creds_map, and removing the AsyncAuth singleton.

Related: #70642, #70603, #70366, #70714.

Versions Report

No user-visible change. Targets the master branch.

Ngôn ngữ chính
Python
Star
15.8k
Fork
5.6k
Merge trung bình
5 ngày 9 giờ
Pull request đã merge (30 ngày)
99

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 saltstack/salt

Tất cả issue của saltstack/salt

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.