fix secrets read stuck
This commit is contained in:
parent
4401916104
commit
7d920907cc
|
|
@ -41,15 +41,20 @@ def _init_seed_via_db() -> bytes:
|
|||
|
||||
# Wait for table to exist
|
||||
start = time.time()
|
||||
# Wait for table existence, reconnecting to avoid stale transactions
|
||||
while True:
|
||||
with engine.connect() as conn:
|
||||
while not db_ready(conn):
|
||||
if db_ready(conn):
|
||||
break
|
||||
time.sleep(0.5)
|
||||
if time.time() - start > 120:
|
||||
raise TimeoutError("service_config table not available")
|
||||
|
||||
def read_seed() -> Optional[bytes]:
|
||||
# Use a fresh connection/session per read to avoid snapshot staleness
|
||||
try:
|
||||
with Session(bind=conn) as s:
|
||||
with engine.connect() as rconn:
|
||||
with Session(bind=rconn) as s:
|
||||
row = s.query(ServiceConfigValue).filter(ServiceConfigValue.key == 'private_key').first()
|
||||
if not row:
|
||||
return None
|
||||
|
|
@ -69,16 +74,13 @@ def _init_seed_via_db() -> bytes:
|
|||
seed = _load_seed_from_env_or_generate()
|
||||
# Try insert; if another primary raced, ignore
|
||||
try:
|
||||
with Session(bind=conn) as s:
|
||||
with engine.connect() as wconn:
|
||||
with Session(bind=wconn) as s:
|
||||
s.add(ServiceConfigValue(key='private_key', packed_value={"value": seed.hex()}))
|
||||
s.commit()
|
||||
make_log("HotWallet", "Seed saved in service_config by primary", level='info')
|
||||
return seed
|
||||
except Exception:
|
||||
try:
|
||||
conn.rollback()
|
||||
except Exception:
|
||||
pass
|
||||
# Read again in case of race
|
||||
seed2 = read_seed()
|
||||
if seed2:
|
||||
|
|
|
|||
Loading…
Reference in New Issue