mirror of
https://github.com/hansjone/netx.git
synced 2026-10-18 05:20:47 +08:00
Fix UME token store sync: load token when expires_at is 0, clear stale memory
Previously exp>mem_exp blocked loading when both were 0 (restart + DB row with missing expiry). Also clear in-memory token when DB row is cleared so token/status matches store after disconnect. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
10ff96f17c
commit
def534e0a6
1 changed files with 29 additions and 3 deletions
|
|
@ -100,16 +100,42 @@ class UMEClient:
|
||||||
except Exception:
|
except Exception:
|
||||||
return
|
return
|
||||||
if not loaded:
|
if not loaded:
|
||||||
|
if self._token_value.strip():
|
||||||
|
self._token_value = ""
|
||||||
|
self._token_expires_at = 0.0
|
||||||
|
self._last_token_source = "memory"
|
||||||
|
self._last_store_sync_changed = True
|
||||||
return
|
return
|
||||||
token, exp = loaded
|
token, exp = loaded
|
||||||
token = str(token or "").strip()
|
token = str(token or "").strip()
|
||||||
if not token:
|
if not token:
|
||||||
return
|
if self._token_value.strip():
|
||||||
if exp > float(self._token_expires_at):
|
self._token_value = ""
|
||||||
self._token_value = token
|
self._token_expires_at = 0.0
|
||||||
self._token_expires_at = float(exp)
|
self._last_token_source = "memory"
|
||||||
self._last_token_source = "db"
|
|
||||||
self._last_store_sync_changed = True
|
self._last_store_sync_changed = True
|
||||||
|
return
|
||||||
|
exp_f = float(exp)
|
||||||
|
mem_exp = float(self._token_expires_at)
|
||||||
|
mem_tok = self._token_value.strip()
|
||||||
|
# Adopt DB when we have no local token, DB has newer expiry, or token string changed.
|
||||||
|
# If DB expiry is missing (0) but we already have the same token with a positive local expiry,
|
||||||
|
# keep local expiry (avoids token_status showing disconnected after restart when DB row is incomplete).
|
||||||
|
adopt = False
|
||||||
|
if not mem_tok:
|
||||||
|
adopt = True
|
||||||
|
elif token != mem_tok:
|
||||||
|
adopt = True
|
||||||
|
elif exp_f > mem_exp:
|
||||||
|
adopt = True
|
||||||
|
elif exp_f <= 0 and not (token == mem_tok and mem_exp > 0):
|
||||||
|
adopt = True
|
||||||
|
if adopt:
|
||||||
|
if token != mem_tok or exp_f != mem_exp:
|
||||||
|
self._last_store_sync_changed = True
|
||||||
|
self._token_value = token
|
||||||
|
self._token_expires_at = exp_f
|
||||||
|
self._last_token_source = "db"
|
||||||
|
|
||||||
def _persist_token_to_store(self) -> None:
|
def _persist_token_to_store(self) -> None:
|
||||||
if self._token_saver is None:
|
if self._token_saver is None:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue