AOSSIE-Org / AOSSIE-Org/PictoPy

BUG: Sync-service: Deadlock when Watcher Self-Restarts after Folder Deletion

Aperta
#1,031 2 commenti 0 reazioni 1 assegnatario Rivendicata da @DeveloperAmrit Vedi su GitHub
backend bug
Lingua principale
Python
Stelle
283
Fork
679
Merge medio
7g 2h
PR unite (30g)
3

Descrizione

### Is there an existing issue for this?

- [x] I have searched the existing issues

### What happened?

### Description
The watcher service freezes and eventually fails when it attempts to restart itself after detecting a deleted folder. The operation times out because the background thread attempts to join itself.

### Steps to Reproduce
1. Start the sync-microservice.
2. Add a folder to the watchlist (this automatically starts the watcher).
3. Manually delete that folder from the filesystem while the service is running.
4. Observe logs: The watcher will log "Processing deleted folders", then hang for 5 seconds before logging a warning about the thread not stopping gracefully.

### Root cause
In watcher.py, the function `watcher_util_watcher_worker` runs inside the background thread watcher_thread.
When a deletion is detected, it calls `watcher_util_restart_folder_watcher()`, which calls `watcher_util_stop_folder_watcher().` Crucially, `watcher_util_stop_folder_watcher()` executes `watcher_thread.join()`. Since this code is running inside watcher_thread, the thread attempts to join itself, causing a deadlock until the 5-second timeout hits.

### Screenshot
Image

### Potential fix
- The worker thread should not handle the restart logic directly. Instead of calling restart:
- The worker should set a "restart_required" flag or signal.
- The worker should simply break out of the loop and return normally.
- The main thread (or a separate monitor thread) should detect the clean exit and trigger the restart logic.

I would like to work on this issue

### Record

- [x] I agree to follow this project's Code of Conduct

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.