AOSSIE-Org / AOSSIE-Org/PictoPy

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

Open
#1,031 2 comments 0 reactions 1 assignee Claimed by @DeveloperAmrit View on GitHub
backend bug
Dominant language
Python
Stars
283
Forks
679
Avg merge
7d 2h
Merged PRs (30d)
3

Description

### 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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.