Skip to content

fix(job): scope lock to --run, fix exit code, remove dead code#238

Open
icciaaron wants to merge 2 commits intoFreePBX:release/17.0from
icciaaron:fix/job-lock-scope-and-cleanup
Open

fix(job): scope lock to --run, fix exit code, remove dead code#238
icciaaron wants to merge 2 commits intoFreePBX:release/17.0from
icciaaron:fix/job-lock-scope-and-cleanup

Conversation

@icciaaron
Copy link
Copy Markdown

Summary

Three issues in fwconsole job that combine to silently prevent time-sensitive jobs (like time condition BLF updates) from executing.

1. Lock scope too broad

The LockableTrait lock is acquired at the top of execute(), blocking all operations — including --list, --enable, and --disable — when a --run is already in progress. These non-destructive operations do not modify job state or interfere with running jobs.

Fix: Move the lock to immediately before the --run dispatch. --list, --enable, and --disable now execute without contention.

2. Lock contention returns exit code 0

When a second fwconsole job --run cannot acquire the lock, it returns 0 (success). Cron, scripts, and monitoring cannot distinguish a successful run from a completely skipped one.

Fix: Return 1 (failure) and wrap the message in <error> tags for console visibility.

3. Dead code block

Lines 61–64 contain a duplicate if(\$input->getOption('disable')) check that is identical to the block at lines 56–59 — making it unreachable. The body references \$input->getOption('run') suggesting it was intended as the --run dispatch but was never corrected.

Fix: Remove the dead block.

Impact

On busy PBXact/FreePBX systems with 27+ registered jobs, a single slow job (calendar sync, firewall update, SangomaConnect keepalive) can hold the process-wide lock past the 60-second cron interval. The next fwconsole job --run silently exits with code 0, skipping all jobs including time-sensitive ones like the timeconditions schedtc job that updates BLF hint states.

With the lock scoped to --run only, administrators can still query and manage jobs (--list, --enable, --disable) during a long-running job execution.

Environment

  • FreePBX 17 / PBXact 17
  • Symfony Console 6.2.x (LockableTrait)
  • PHP 8.1+ (Debian 12)

Related


Discovered during fleet maintenance by Aaron Salsitz (Master Bitherder) at ICCI, LLC. Analysis and fix developed with Claude Code.

icciaaron and others added 2 commits April 16, 2026 10:44
Three issues in the fwconsole job command:

1. Lock acquired too early: the LockableTrait lock was acquired at
   the top of execute(), blocking --list, --enable, and --disable
   when a --run was already in progress. These non-destructive
   operations do not need mutual exclusion.

2. Lock contention returned exit code 0 (success). Cron and scripts
   could not detect that the job run was skipped. Return 1 and wrap
   the message in <error> tags for console visibility.

3. Dead code: duplicate if($input->getOption('disable')) block at
   line 61 (copy-paste of the block at line 56) was unreachable and
   contained unrelated runJobs() logic.

Move the lock to immediately before the --run dispatch so that
--list, --enable, and --disable execute without contention.

Reported-by: Aaron Salsitz <asalsitz@icci.com>
Co-Authored-By: Claude Code <noreply@anthropic.com>
The lock must only be acquired when --run is present. Without this
gate, running `fwconsole job` with no arguments (help display) would
unnecessarily contend for the lock and show an error instead of help
when another --run is in progress.

Consolidate the two --run branches (run-all vs run-specific) into a
single --run block for clarity.

Co-Authored-By: Claude Code <noreply@anthropic.com>
@icciaaron
Copy link
Copy Markdown
Author

Hi @jissphilip @kapilgupta01 — this one scopes the --run lock so it doesn't block other fwconsole job operations, fixes an incorrect exit code, and drops some dead code. We hit this while debugging a cron issue on customer systems. Happy to adjust anything that doesn't match your preferences.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant