Skip to content

fix(process): stop waiting out the worker registration window (#479) - #494

Merged
TheWitness merged 4 commits into
developfrom
fix/worker-wait-exited-479
Dec 3, 2026
Merged

TheWitness merged 4 commits into
developfrom
fix/worker-wait-exited-479

Conversation

@TheWitness

Copy link
Copy Markdown
Member

Addresses the defect found while investigating #479.

Problem

syslog_wait_workers() held the master in its registration stage until every launched worker was registered and still running. Workers that had already finished, or that exited early because the processing-lock check failed, never counted. Every parallel phase therefore waited the full 10-second grace window:

The completion check also used read_config_option(), which caches per process. A value read during the references phase could be returned again during the transfer phase.

Change

  • A worker counts as accounted for once it is registered or has recorded its statistics. Child numbers from the process table (taskid) and from stats_syslog_child_N are merged rather than added, so a worker between writing its stats and unregistering isn't counted twice.
  • Stats are read fresh from settings (syslog_workers_reported()) for both the wait and the "exited without recording completion" warning.
  • When the lock check fails, the worker records a success: false stats row (reason: lock) so the master stops waiting and the phase counts as failed. It also logs the expected owner and what IS_USED_LOCK() returned, e.g. (expected connection 54, IS_USED_LOCK returned NULL), so the cause behind Latest Develop branch, new error message: One or more transfer workers failed #479 can be diagnosed from the log. That root cause is still pending reporter information.

Verification

  • New regression tests in tests/Unit/SyslogWorkerWaitTest.php. The "already finished" case fails on develop after the 10.02 s wait and passes with this change.
  • Full Pest suite (Cacti develop, PHP 8.3, memory_limit=2G): 892 passed.
  • End to end on Cacti develop with 2 workers and 500 messages: run time dropped from 11.2 s to 1.48 s, and all records transferred.
  • Starting a worker with a non-holding --lock-owner logs IS_USED_LOCK returned NULL, writes the failed stats row, exits 1, and leaves no process row.
  • php -l is clean. php-cs-fixer reports no new findings in the changed hunks, and PHPStan level 6 reports nothing on the new functions.

syslog_wait_workers() held the master in its registration stage until
every launched worker was registered and running. Workers that had
already finished, or exited because the processing lock check failed,
were never counted, so each parallel phase waited the full ten seconds.
A worker now counts once it is registered or has recorded statistics,
read from the settings table rather than the read_config_option() cache,
and the completion check uses the same fresh read.

A worker that finds the processing lock no longer held by its master
records a failed statistics row so the master stops waiting, and logs
the expected owner and the holder IS_USED_LOCK() reported.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Late reports from an earlier run can prematurely end the current registration wait because reports are not scoped by run ID and phase.

2 open issues
What changed in this PR

Reduces unnecessary delays in parallel Syslog processing and improves diagnostics for lock failures related to #479.

Changes:

  • Counts running and completed workers without double-counting.
  • Reads completion reports directly from settings and records lock-check failures.
  • Adds regression tests and documents the fix.
File Description
tests/​Unit/​SyslogWorkerWaitTest.php Tests completed-worker accounting and duplicate counting.
tests/​Unit/​ProcessingLockTest.php Tests lock-holder reporting.
syslog_process.php Records worker lock failures and diagnostic details.
includes/​functions.php Updates worker accounting and adds lock-holder lookup.
CHANGELOG.md Documents the #479 timing and diagnostic improvements.

Review effort: Balanced

Comment thread includes/functions.php Resolved
Comment thread tests/Unit/SyslogWorkerWaitTest.php Resolved
Address review on #494. A child of an earlier run could report after the
next run cleared the statistics rows and end its registration wait or be
counted as its result. The wait, the completion check and the transfer
aggregation now count only reports whose run_id and phase match, and a
child that fails the lock check records its failure only while the lock
is free, so it never overwrites a newer run's rows. The double-count
regression test now asserts the exact poll count.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
@sonarqubecloud

sonarqubecloud Bot commented Dec 3, 2026

Copy link
Copy Markdown

@TheWitness
TheWitness merged commit b57a5ba into develop Dec 3, 2026
11 checks passed
@TheWitness
TheWitness deleted the fix/worker-wait-exited-479 branch December 3, 2026 11:48
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.

4 participants