fix: executionTimeLimit no longer blocks graceful shutdown#680
Merged
Conversation
Cap the per-poll receive timeout with min(executionTimeLimit, receiveTimeoutInMilliseconds) instead of letting executionTimeLimit fully override the channel's configured receive timeout in EnqueueInboundChannelAdapter (DBAL/SQS/Redis), AmqpStreamInboundChannelAdapter, and KafkaInboundChannelAdapter. Previously a consumer started with a large executionTimeLimit (e.g. --executionTimeLimit 3600000) could block inside a single broker receive() call for the full duration while idle, ignoring SIGTERM/SIGINT/SIGQUIT and its own time limit until that call returned. Fixes #440
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why is this change proposed?
When a consumer configured with
executionTimeLimit(e.g.ecotone:run internal --executionTimeLimit 3600000) has no messages to process, it fails to respond to SIGTERM/SIGINT/SIGQUIT or even its own time limit in a timely manner. The root cause: DBAL/AMQP/SQS/Redis/Kafka inbound channel adapters usedexecutionTimeLimitas the timeout for a single blocking brokerreceive()call, fully overriding the channel's normal, shortreceiveTimeoutInMilliseconds. In production this means a consumer with a 1-hour execution time limit sits blocked inside one broker call for up to an hour before ever checking for termination — breaking graceful shutdown in containerized/orchestrated environments (Kubernetes SIGTERM during pod termination,docker stop, etc). Fixes #440.Description of Changes
min(executionTimeLimit, receiveTimeoutInMilliseconds)instead of lettingexecutionTimeLimitfully override it, inEnqueueInboundChannelAdapter(covers DBAL, SQS, Redis),AmqpStreamInboundChannelAdapter, andKafkaInboundChannelAdapter.PollingMetadata::withTestingSetup()intentionally sets a smallexecutionTimeLimitto shorten polling in tests) while fixing production runs whereexecutionTimeLimitis large.ExecutionTimeLimitReceiveTimeoutTest— a fast, low-level reproduction proving the receive call now respects the channel's configured timeout instead of the execution time limit.GracefulShutdownOnSignalTest— an end-to-end reproduction that sends a realSIGTERMto a running consumer (mirroring the issue's exact repro steps) and asserts it shuts down promptly instead of ignoring the signal.maxExecutionTimeInMillisecondsin several Kafka tests that consume multiple messages within a single time-boundedrun()call, from the pre-existing consumer-group rebalancing floor (10000ms) up to 20000ms — those tests had no margin for a second poll cycle and were prone to flaking under load (unrelated to the fix itself, but surfaced while validating it).No code changes needed for end users — consumers configured with
executionTimeLimitnow behave correctly out of the box:Use case scenarios:
executionTimeLimitand no traffic could ignore that signal for the full duration.executionTimeLimitpurely as a safety net (e.g., process restarted hourly by a supervisor) — these silently failed to self-terminate on schedule when idle.Ctrl+C(SIGINT) is sent to a running consumer, expecting immediate shutdown.sequenceDiagram participant OS participant InterceptedConsumer participant SignalInterceptor participant Adapter as Inbound Channel Adapter participant Broker Note over InterceptedConsumer,Broker: Before fix InterceptedConsumer->>Adapter: poll (timeout = executionTimeLimit, e.g. 3600000ms) Adapter->>Broker: receive(3600000ms) OS--)InterceptedConsumer: SIGTERM Note right of InterceptedConsumer: signal flagged but not checked -<br/>still blocked inside receive() Broker--)Adapter: (nothing, up to 1 hour later) Note over InterceptedConsumer,Broker: After fix InterceptedConsumer->>Adapter: poll (timeout = min(3600000, 1000)ms) Adapter->>Broker: receive(1000ms) OS--)InterceptedConsumer: SIGTERM Broker--)Adapter: null (timeout) Adapter--)InterceptedConsumer: control returns InterceptedConsumer->>SignalInterceptor: shouldBeStopped() SignalInterceptor--)InterceptedConsumer: true InterceptedConsumer->>InterceptedConsumer: graceful shutdownPull Request Contribution Terms