Skip to content

Fix #347: Install SignalLoop signal handlers only while consuming - #348

Open
samdark wants to merge 4 commits into
masterfrom
fix-347-signal-loop-handlers
Open

samdark wants to merge 4 commits into
masterfrom
fix-347-signal-loop-handlers

Conversation

@samdark

@samdark samdark commented Oct 27, 2026 •

Copy link
Copy Markdown
Member

Fixes #347.

Keep existing application signal handlers intact when a SignalLoop is created. Queue consumers and commands take over signal handling while processing messages, finish the current message before stopping, and restore application handlers when processing ends or fails. Commands that process several queues keep graceful shutdown active between queues.

Add ScopedLoopInterface for custom loops that need setup and cleanup around consumption. Preserve standalone canContinue() behavior, where the loop keeps its signal handlers for the rest of the process. Document how to stop and pause workers, share a loop when configuring commands manually, and restore handlers in custom execution loops.

Summary by Sourcery

Scope SignalLoop signal handling to message consumption while preserving application handlers and graceful shutdown behavior.

New Features:

  • Add scoped loop lifecycle support for setting up and cleaning up process-wide state around message consumption.
  • Allow commands to share a loop instance so graceful shutdown remains active across multiple queues.

Bug Fixes:

  • Preserve existing application signal handlers when creating a SignalLoop and restore them after consumption or processing failures.
  • Ensure workers finish the current message and stop before processing subsequent messages after a shutdown signal.

Enhancements:

  • Support nested loop scopes and retain standalone canContinue() behavior for long-lived signal handling.

Documentation:

  • Document graceful worker stopping and pausing, manual command loop sharing, custom execution-loop cleanup, and ScopedLoopInterface usage.

Tests:

  • Add coverage for signal-handler preservation, restoration, nested scopes, graceful shutdown, queue boundaries, and failure handling.

@codecov

codecov Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.15%. Comparing base (ab17e34) to head (8af7835).

Additional details and impacted files
@@             Coverage Diff              @@
##             master     #348      +/-   ##
============================================
+ Coverage     94.90%   95.15%   +0.24%     
- Complexity      375      395      +20     
============================================
  Files            59       59              
  Lines           981     1031      +50     
============================================
+ Hits            931      981      +50     
  Misses           50       50              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread src/Cli/SignalLoop.php Resolved
Comment thread src/QueueConsumer.php Resolved
…-pause` in test

- `RunCommand` accepts an optional loop and starts it once around all queues, so a signal received between two
  queues sets the exit flag instead of reaching the default handler.
- Document and test that handlers installed by `canContinue()` outside of `start()`/`finish()` are kept.
- Pass `--pause` through `ArrayInput` parameters, since `Command::run()` re-binds the input.
@samdark
samdark force-pushed the fix-347-signal-loop-handlers branch from 1f82e0e to 92b07c7 Compare October 29, 2026 21:56

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Sourcery assessment

Approved.

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.

SignalLoop constructor overrides existing signal handlers, breaking graceful shutdown in Symfony Console commands

2 participants