davsclaus commented on code in PR #30786:
URL: https://github.com/apache/camel/pull/30786#discussion_r4695203938


##########
components/camel-mongodb/src/main/java/org/apache/camel/component/mongodb/MongoAbstractConsumerThread.java:
##########
@@ -183,13 +183,21 @@ protected void stop() throws Exception {
             cursor.close();
         }
         awaitStopped();
+        afterStopped();

Review Comment:
   The thread is only left behind when MongoDB stopped answering, and in that 
state the `updateOne` that `afterStopped()` now does on the stopping thread can 
block on driver timeouts. That partly undoes the bounded stop of CAMEL-27010. 
If it throws, the exception leaves `stop()`, and 
`MongoDbTailableCursorConsumer.doStop()` (lines 41-45) skips the executor 
shutdown, so the pool leaks.
   
   On a normal stop the thread has already persisted in the `finally` of 
`doRun()`, so every stop now does a redundant second `updateOne`.
   
   Suggestion: call the hook only when the thread was left behind (for example, 
`awaitStopped()` returns whether it gave up), and catch and log at WARN so the 
stop still completes.



##########
components/camel-mongodb/src/main/java/org/apache/camel/component/mongodb/MongoDbTailingThread.java:
##########
@@ -148,6 +148,15 @@ protected void doRun() {
         }
     }
 
+    /**
+     * Persists the tail position once the thread has ended, so that a test or 
caller reading the tracking document
+     * right after {@code stopRoute} sees the last routed record.
+     */
+    @Override
+    protected void afterStopped() {
+        tailTracking.persistToStore();

Review Comment:
   Nit on the Javadoc above: production docs should state the behavior 
("persists the tail position from the thread that stops the consumer, as a 
thread left behind may persist only much later") rather than mention a test.
   
   Also see the review body on the visibility of `lastVal`: this runs on the 
stopping thread, and in the left-behind case nothing makes the consumer 
thread's last `setLastVal` visible to it.



-- 
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