docs: add worker running deadlock fix report
This commit is contained in:
@@ -0,0 +1,112 @@
|
|||||||
|
---
|
||||||
|
title: Worker Running Status Deadlock Fix
|
||||||
|
version: 1.0
|
||||||
|
date: 2026-09-18
|
||||||
|
author: Core Team
|
||||||
|
status: completed
|
||||||
|
---
|
||||||
|
|
||||||
|
# Worker Running Status Deadlock Fix
|
||||||
|
|
||||||
|
**Date**: 2026-09-18
|
||||||
|
**Commit**: `0fe09af`
|
||||||
|
**Issue**: UI "Deep Scan" button causes worker deadlock
|
||||||
|
|
||||||
|
## Problem Description
|
||||||
|
|
||||||
|
Users reported that clicking the UI "Deep Scan" button would cause the system to hang indefinitely. Investigation revealed:
|
||||||
|
|
||||||
|
1. `processor_results` table had records with `status='running'`
|
||||||
|
2. But processors were never actually started (no subprocess)
|
||||||
|
3. Worker would detect 'running' status and skip these processors
|
||||||
|
4. This created an infinite loop: Worker expected 7 processors to complete, but only 1 (CUT) was done
|
||||||
|
|
||||||
|
## Root Cause
|
||||||
|
|
||||||
|
**File**: `/Users/accusys/momentry_core/src/worker/job_worker.rs`
|
||||||
|
|
||||||
|
**Bug Location**: Lines 590-600 and 1434-1494
|
||||||
|
|
||||||
|
**Timeline**:
|
||||||
|
1. Worker started `process_job()` loop
|
||||||
|
2. Line 591-600: Set status to 'running' (via `update_processor_progress`)
|
||||||
|
3. Line 1434: Check concurrent capacity limit
|
||||||
|
4. If limit reached: Mark as 'skipped' (via `upsert_processor_result`)
|
||||||
|
5. **PROBLEM**: Status was set to 'running' BEFORE checking capacity
|
||||||
|
6. If `upsert_processor_result` failed or was interrupted, status stayed 'running'
|
||||||
|
7. Next poll cycle: Worker sees 'running' and skips processor → deadlock
|
||||||
|
|
||||||
|
### Code Flow (Before Fix)
|
||||||
|
|
||||||
|
```rust
|
||||||
|
for processor_type in &processors_to_run {
|
||||||
|
// Step 1: Set status to 'running' (PREMATURE!)
|
||||||
|
self.db.update_processor_progress(..., "running").await?;
|
||||||
|
|
||||||
|
// Step 2: Check if file exists...
|
||||||
|
// Step 3: Check capacity (TOO LATE!)
|
||||||
|
if !self.processor_pool.can_start_for_job(job.id).await {
|
||||||
|
// Mark as 'skipped' - but may fail!
|
||||||
|
self.db.upsert_processor_result(..., "skipped").await?;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Solution
|
||||||
|
|
||||||
|
**Move capacity check BEFORE setting 'running' status**
|
||||||
|
|
||||||
|
### Code Flow (After Fix)
|
||||||
|
|
||||||
|
```rust
|
||||||
|
for processor_type in &processors_to_run {
|
||||||
|
// Step 1: Check capacity FIRST
|
||||||
|
if !self.processor_pool.can_start_for_job(job.id).await {
|
||||||
|
// Mark as 'skipped' immediately
|
||||||
|
self.db.upsert_processor_result(..., "skipped").await?;
|
||||||
|
continue; // Skip to next processor
|
||||||
|
}
|
||||||
|
|
||||||
|
// Step 2: Only set 'running' if capacity is available
|
||||||
|
self.db.update_processor_progress(..., "running").await?;
|
||||||
|
|
||||||
|
// Step 3: Continue to start processor...
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Changes Made
|
||||||
|
|
||||||
|
**File**: `src/worker/job_worker.rs`
|
||||||
|
|
||||||
|
1. **Lines 591-633** (NEW): Added capacity check before `update_processor_progress`
|
||||||
|
2. **Removed**: Duplicate capacity check at lines 1464-1493
|
||||||
|
|
||||||
|
## Impact
|
||||||
|
|
||||||
|
### Before Fix
|
||||||
|
- UI "Deep Scan" → Worker deadlock
|
||||||
|
- `processor_results` stuck at 'running'
|
||||||
|
- Users cannot process videos
|
||||||
|
|
||||||
|
### After Fix
|
||||||
|
- Capacity checked before setting status
|
||||||
|
- No more 'running' status deadlocks
|
||||||
|
- UI "Deep Scan" works correctly
|
||||||
|
|
||||||
|
## Testing
|
||||||
|
|
||||||
|
1. Cleaned all jobs for test file: `1ad54677a8ad5a44c6c8cad1f4c21595`
|
||||||
|
2. Restarted worker with new code
|
||||||
|
3. Ready for UI testing
|
||||||
|
|
||||||
|
## Related Issues
|
||||||
|
|
||||||
|
- Face detection threshold bug (fixed in `31d1b405`)
|
||||||
|
- Worker infinite loop (this fix)
|
||||||
|
|
||||||
|
## Next Steps
|
||||||
|
|
||||||
|
- Monitor for any new deadlock reports
|
||||||
|
- Consider adding timeout mechanism for 'running' status
|
||||||
|
- Add logging for capacity limit triggers
|
||||||
Reference in New Issue
Block a user