shashank created CAMEL-27091:
--------------------------------

             Summary: camel-mongodb-gridfs - each stop of the consumer leaves a 
thread waiting for ever for the polls
                 Key: CAMEL-27091
                 URL: https://issues.apache.org/jira/browse/CAMEL-27091
             Project: Camel
          Issue Type: Bug
          Components: camel-mongodb-gridfs
            Reporter: shashank
            Assignee: shashank


h3. What happens

{{GridFsConsumer}} runs {{run()}} on a thread of its own executor. {{run()}} 
builds a {{BackgroundTask}} with an unlimited duration and calls 
{{task.run(...)}}, which schedules the polls on {{taskExecutor}} and waits 
until the task ends. A poll never ends the task (it returns false whatever it 
found, also when it fails).

{{doStop}} shuts {{taskExecutor}} down, which cancels the scheduled polls, and 
shuts down the executor without interrupting it. Nothing releases the thread in 
{{run()}}: every stop of the consumer (route stop and start, route reload) 
leaves one thread waiting for ever, and the task stays in the task registry.

h3. How it was found

Found with a TLA+ model of the thread in {{run()}}, the poll thread and the 
stop, checked with TLC. On main the invariant "after the stop, no thread waits 
on a latch that nothing can count down" is violated in 25 states (start, polls, 
stop), and no behaviour of main reaches a stopped consumer whose {{run()}} has 
returned. Keeping {{task.run}} and cancelling the task in doStop fixes that but 
interrupts a poll that is routing files (the finally of 
{{waitForTaskCompletion}} cancels the future with interrupt). The fix below 
holds all three properties (no stranded thread, no interrupted poll, no task 
left registered; 52 distinct states).

h3. How to reproduce

{{GridFsConsumerTimestampTest.stopLeavesNoThreadWaitingForThePolls}} (fake 
bucket): start the consumer, wait for two polls, stop it: its thread is still 
in {{run()}} 20 seconds later.

h3. Fix

{{run()}} schedules the polls with {{task.schedule(...)}} instead of waiting 
for the task, keeps the task, and does not schedule when the consumer is 
already stopping; {{doStop}} cancels the task without interrupt, so a poll that 
runs finishes its files and the task leaves the registry.

_Filed with Claude Code on behalf of allthingssecurity._



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to