Spaces:
Paused
Paused
fix: sync thread waits for restore to finish before starting
Browse filesPrevent 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>
- 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
|
|
|
|
|
|
|
| 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 |
|