Skip to content

Add --memory-limit, signal handling and graceful_max_execution to rabbitmq:rpc-server#747

Open
qwant50 wants to merge 3 commits into
php-amqplib:masterfrom
qwant50:feature/rpc-server-memory-limit
Open

Add --memory-limit, signal handling and graceful_max_execution to rabbitmq:rpc-server#747
qwant50 wants to merge 3 commits into
php-amqplib:masterfrom
qwant50:feature/rpc-server-memory-limit

Conversation

@qwant50

@qwant50 qwant50 commented Jul 19, 2026

Copy link
Copy Markdown

Closes #746. Supersedes #524. Refs #712, #457, #545.

Makes the RPC server a first-class consumer:

  • RpcServerCommand now extends BaseConsumerCommand, inheriting --memory-limit|-l, --without-signals|-w and graceful SIGTERM/SIGINT/SIGQUIT handling.
  • The consume/memory/graceful-execution machinery moves from Consumer up into BaseConsumer (verbatim), so RpcServer inherits it. The memory check now lives in maybeStopConsumer(), one enforcement point for all consumer variants.
  • rpc_servers config gains idle_timeout, idle_timeout_exit_code, timeout_wait and graceful_max_execution.
  • Event type hints widened ConsumerBaseConsumer (BC-safe widening).

Fixes over #524: memory limit was never actually enforced on the RPC path; graceful_max_execution was wired in the extension but missing from Configuration.php (config would be rejected); event constructors type-hinted concrete Consumer and would TypeError; execute() lacked the int return; SIGQUIT was missing.

BC notes: RPC loop switches start()consume() (dispatches OnConsume/OnIdle events, honors idle timeout; start() kept for programmatic users). --debug becomes a flag (VALUE_NONE). --route and --without-signals newly inherited (defaults preserve old behavior). SIGTERM now finishes the current message before exiting. The memory-limit check moved into maybeStopConsumer(), so it now also runs between messages: an idle consumer over the limit stops on the next loop tick instead of only after processing a message (the force-stop flag is raised so the loop exits cleanly rather than re-entering wait()). Important for existing listeners: on_consume/on_idle events can now carry an RpcServer instance where previously only Consumer was possible — if a listener calls Consumer-only methods (purge(), delete()) on $event->getConsumer() without an instanceof Consumer guard, it will now fatal the first time it fires for an RPC server.

Tests: memory-limit stop behavior in RpcServerTest, new RpcServerCommandTest for the input definition, DI wiring fixture + assertions for the new rpc_servers options. Full suite + PHPStan pass; README updated.

…max_execution

Makes the RPC server a first-class consumer: RpcServerCommand now extends
BaseConsumerCommand, and the consume/memory/graceful-execution machinery
moves from Consumer into BaseConsumer so RpcServer inherits it.

Closes php-amqplib#746. Supersedes php-amqplib#524. Refs php-amqplib#712, php-amqplib#457.
@qwant50
qwant50 requested a review from mihaileu as a code owner July 19, 2026 17:17
qwant50 added 2 commits July 19, 2026 19:30
When the memory limit was already exceeded at the top of the consume()
loop, maybeStopConsumer() cancelled the consumer but wait() was still
entered and could block forever (timeout 0 with no idle_timeout set).
Raise the force-stop flag as well, so the loop skips wait() and returns.

Also covers the relocated memory check with Consumer/DynamicConsumer
tests and reformats the new README paragraph.
…argument

BaseConsumerCommand labels its argument 'Consumer Name', which read oddly
in 'rabbitmq:rpc-server --help'. Override it back to 'Server Name'.
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.

rabbitmq:rpc-server lacks --memory-limit and graceful signal handling

1 participant