fix: align in-memory authentication semantics

This commit is contained in:
2026-07-22 16:27:24 +08:00
parent a174a22bcb
commit 25c4fbe089
2 changed files with 71 additions and 2 deletions
+8 -2
View File
@@ -106,6 +106,9 @@ func NewClientWithAuthData(authData AuthData, options ...ClientOption) (*Client,
if err != nil {
return nil, err
}
if !authData.zero() {
authData = client.authDataWithIdentity(authData)
}
client.setAuthData(authData)
return client, nil
}
@@ -131,8 +134,11 @@ func newClient(options ...ClientOption) (*Client, error) {
return client, nil
}
// WithAuthDataChanged configures serialized persistence for in-memory auth updates.
// The callback runs under login serialization, but never while the auth data lock is held.
// WithAuthDataChanged configures synchronous persistence for in-memory auth updates.
// The callback is serialized by the client's login lock and may acquire unrelated
// application locks, but it must not call Client methods other than AuthData.
// In particular, calling Login or another method that may refresh authentication
// will deadlock. Returning an error leaves the client's authentication unchanged.
func WithAuthDataChanged(callback func(AuthData) error) ClientOption {
return func(client *Client) error {
if callback == nil {