RockteMQ-AI commented on issue #1331:
URL: 
https://github.com/apache/rocketmq-clients/issues/1331#issuecomment-5263024182

   **Issue Evaluation**
   
   Category: `type/bug` | Status: **Confirmed**
   
   The reported infinite recursion has been verified against the current 
codebase (`python/rocketmq/v5/consumer/push/push_consumer.py`).
   
   **Root Cause:**
   `__execute_receive_later` (line 269) calls `__execute_receive` 
**synchronously** after `time.sleep(1)`. When the cache is full, the call chain 
becomes:
   
   ```
   __execute_receive → __execute_receive_later → __execute_receive → 
__execute_receive_later → ...
   ```
   
   Each cycle adds 2+ frames to the call stack. If the cache remains full 
(e.g., slow consumer, backpressure), the stack grows until Python raises 
`RecursionError` (default limit ~1000 frames ≈ 500 cycles).
   
   **Reproduction path:**
   1. `__execute_receive` (line 226) detects `process_queue.is_cache_full()` → 
calls `__execute_receive_later` (line 237)
   2. `__execute_receive_later` (line 269) sleeps 1s, then calls 
`__execute_receive` directly (line 271)
   3. If cache is still full → repeat from step 1
   
   **Impact:** PushConsumer crashes with `RecursionError` under sustained 
backpressure or slow consumption.
   
   **Severity:** High — consumer process termination under load.
   
   **Suggested fix:**
   Replace the synchronous recursive call with a timer-based or 
thread-pool-based scheduling:
   ```python
   def __execute_receive_later(self, message_queue, process_queue, attempt_id):
       # Instead of synchronous recursion, schedule on the executor
       self.__receive_message_executor.submit(
           functools.partial(self.__delayed_execute_receive, message_queue, 
process_queue, attempt_id)
       )
   
   def __delayed_execute_receive(self, message_queue, process_queue, 
attempt_id):
       time.sleep(PushConsumer.RECEIVE_RETRY_DELAY)
       self.__execute_receive(message_queue, process_queue, attempt_id)
   ```
   
   Alternatively, use `threading.Timer` to break the call stack.
   
   An automated fix proposal will be generated. Reply `/approve` to proceed 
with PR generation.
   
   ---
   *Automated evaluation by RockteMQ-AI*


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to