tao-shen Claude Opus 4.6 commited on
Commit
54cbddc
Β·
1 Parent(s): 80c4d9b

fix: sync thread waits for restore to finish before starting

Browse files

Prevent race condition where sync rsync writes to /data/ while
snapshot_download is still populating it.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

Files changed (1) hide show
  1. entrypoint.py +9 -1
entrypoint.py CHANGED
@@ -345,9 +345,15 @@ def save_and_upload():
345
  log(f"══ SYNC: done ({elapsed_all:.1f}s) β€” {uploaded} ok, {failed} failed ══")
346
 
347
 
 
 
 
 
348
  # ── Sync Thread ───────────────────────────────────────────────────────
349
  def sync_loop():
350
- log("sync thread: waiting 30s before first sync")
 
 
351
  time.sleep(30)
352
  cycle = 0
353
  while True:
@@ -533,6 +539,8 @@ def main():
533
  log("── background restore complete ──")
534
  except Exception as e:
535
  log(f"── background restore error: {e} ──")
 
 
536
 
537
  threading.Thread(target=background_restore, daemon=True).start()
538
 
 
345
  log(f"══ SYNC: done ({elapsed_all:.1f}s) β€” {uploaded} ok, {failed} failed ══")
346
 
347
 
348
+ # Event to signal restore completion (sync must wait)
349
+ restore_done = threading.Event()
350
+
351
+
352
  # ── Sync Thread ───────────────────────────────────────────────────────
353
  def sync_loop():
354
+ log("sync thread: waiting for restore to finish ...")
355
+ restore_done.wait()
356
+ log("sync thread: restore done, waiting 30s before first sync")
357
  time.sleep(30)
358
  cycle = 0
359
  while True:
 
539
  log("── background restore complete ──")
540
  except Exception as e:
541
  log(f"── background restore error: {e} ──")
542
+ finally:
543
+ restore_done.set() # unblock sync thread
544
 
545
  threading.Thread(target=background_restore, daemon=True).start()
546