Repository navigation
Description
Description
ProcessManager::doExecute() saves the current ProcessHistory of the parent process and restores it only when the process succeeds: the catch block rethrows without restoring it. Symptoms:
- when a sub-process fails and the parent goes on (
process_executortask witherror_strategy: skip), every later log of the parent process is tagged with the sub-processprocess_id/process_code/process_context(added by the log processors fromProcessManager::getProcessHistory()); - in a long-running worker (Messenger / scheduler of the UI bundle), after a failed process,
getProcessHistory()keeps returning the failed one: logs written between two processes are attributed to it. TheprocessedIterables/processedBlockingsarrays are not reset either after an exception, andProcessManagerdoes not implementResetInterface(nokernel.resettag).
Reproduction
clever_age_process:
configurations:
demo.subprocess_failure:
tasks:
start:
task: constant_output
options: { output: 'x' }
outputs: [sub, log]
sub:
task: process_executor
options: { process: demo.subprocess_failure_child }
error_strategy: skip
log:
task: logger
options: { level: warning, message: 'PARENT_MARKER' }
demo.subprocess_failure_child:
public: false
tasks:
fail:
task: constant_output
options: { output: 'not-a-date' }
outputs: [parse]
parse:
task: transformer
options:
transformers:
date_parser: { format: 'Y-m-d' }$ bin/console cleverage:process:execute demo.subprocess_failure
$ grep PARENT_MARKER var/log/dev.log
cleverage_process_task.WARNING: PARENT_MARKER {"input":"x"} {"process_id":1792076636.551416,"process_code":"demo.subprocess_failure_child",...,"task_code":"log",...}
Expected: "process_code":"demo.subprocess_failure" (the log task belongs to the parent process).
Tested on main (74939b2), PHP 8.5, Symfony 7.4.
Cause
ProcessManager::doExecute(): $this->processHistory = $parentProcessHistory; is after the try / catch, so it is skipped when the catch rethrows. The only consumer of ProcessManager::getProcessHistory() is AbstractProcessor::addProcessInfoToRecord().
Proposed fix
- Restore the parent history in a
finallyblock. - Implement
Symfony\Contracts\Service\ResetInterfaceonProcessManager(resetprocessHistory,processedIterables,processedBlockings) and tag the servicekernel.reset, as recommended for stateful services used in long-running processes. - Unit test: failing sub-process caught by the parent, then
getProcessHistory()returns the parent history;reset().
Found during the Symfony bundle best practices review (stateful services / kernel.reset).
Requirements
- Documentation updates
- Reference
- Cookbooks
- Changelog
- Unit tests
Breaking changes
None: only the history returned by getProcessHistory() after a failure changes (it was wrong); reset() is a new method.
Activity
Merge pull request #302 from cleverage/301