gnodet-bot commented on code in PR #30466:
URL: https://github.com/apache/camel/pull/30466#discussion_r4639863818
##########
components/camel-box/camel-box-component/src/main/java/org/apache/camel/component/box/BoxConsumer.java:
##########
@@ -75,15 +104,67 @@ public void onEvent(BoxEvent event) {
@Override
public void onNextPosition(long position) {
- // noop
+ nextPosition = position;
+ lock.lock();
+ try {
+ // the event stream works again
+ restartDelay = RESTART_DELAY;
+ } finally {
+ lock.unlock();
+ }
}
+ /**
+ * Called by the event stream when it fails (for example when Box cannot
be reached for a while). The event stream
+ * has stopped itself by then and is never started again by the Box SDK:
listen again after a delay, else the
+ * consumer stays started without receiving any event.
+ */
@Override
public boolean onException(Throwable e) {
getExceptionHandler().handleException(RuntimeCamelException.wrapRuntimeCamelException(e));
+ scheduleRestart();
return true;
}
+ private void scheduleRestart() {
+ lock.lock();
+ try {
+ if (!isRunAllowed() || restartExecutor == null) {
+ return;
+ }
+ long delay = restartDelay;
+ restartDelay = Math.min(restartDelay * 2, MAX_RESTART_DELAY);
+ LOG.info("The Box event stream stopped, listening for events again
in {} ms", delay);
+ restartExecutor.schedule(this::restart, delay,
TimeUnit.MILLISECONDS);
+ } finally {
+ lock.unlock();
+ }
+ }
+
+ private void restart() {
+ lock.lock();
+ try {
+ if (!isRunAllowed()) {
+ return;
+ }
+ Long position = nextPosition != null ? nextPosition :
startingPosition();
+ apiProxy.stopListening();
+ apiProxy.listen(this, position);
+ LOG.info("Listening for Box events again from position {}",
position != null ? position : "now");
Review Comment:
⚠️ **Lock held during network I/O:** `restart()` holds the consumer's
`ReentrantLock` while calling `apiProxy.stopListening()` and
`apiProxy.listen()`. When `position` is null (no `startingPosition` configured
and no events received yet), `listen()` triggers `EventStream.start()`, which
makes a synchronous `GET /events?stream_position=now` to Box with no connect or
read timeout in the SDK (box-java-sdk 4.16.4 default). This blocks `doStop()`
from acquiring the same lock for the duration of that HTTP request —
potentially minutes on an unreachable Box instance.
The PR description acknowledges this: _"a stop that comes while a restart
without a position asks Box for the 'now' position waits for that request"_.
Before this PR, `doStop()` was lock-free; the new lock amplifies the
pre-existing SDK limitation into a potential shutdown hang.
Options:
- Release the lock before calling `listen()`, re-acquire it afterwards with
an `isRunAllowed()` re-check
- Set a `connectTimeout`/`readTimeout` on the `BoxAPIConnection` in
`doStart()` before creating the `BoxEventsManager`
##########
components/camel-box/camel-box-component/src/main/java/org/apache/camel/component/box/BoxConsumer.java:
##########
@@ -75,15 +104,67 @@ public void onEvent(BoxEvent event) {
@Override
public void onNextPosition(long position) {
- // noop
+ nextPosition = position;
+ lock.lock();
+ try {
+ // the event stream works again
+ restartDelay = RESTART_DELAY;
+ } finally {
+ lock.unlock();
+ }
}
+ /**
+ * Called by the event stream when it fails (for example when Box cannot
be reached for a while). The event stream
+ * has stopped itself by then and is never started again by the Box SDK:
listen again after a delay, else the
+ * consumer stays started without receiving any event.
+ */
@Override
public boolean onException(Throwable e) {
getExceptionHandler().handleException(RuntimeCamelException.wrapRuntimeCamelException(e));
+ scheduleRestart();
return true;
}
+ private void scheduleRestart() {
+ lock.lock();
+ try {
+ if (!isRunAllowed() || restartExecutor == null) {
+ return;
+ }
+ long delay = restartDelay;
+ restartDelay = Math.min(restartDelay * 2, MAX_RESTART_DELAY);
+ LOG.info("The Box event stream stopped, listening for events again
in {} ms", delay);
+ restartExecutor.schedule(this::restart, delay,
TimeUnit.MILLISECONDS);
+ } finally {
+ lock.unlock();
+ }
+ }
+
+ private void restart() {
+ lock.lock();
+ try {
+ if (!isRunAllowed()) {
+ return;
+ }
+ Long position = nextPosition != null ? nextPosition :
startingPosition();
+ apiProxy.stopListening();
+ apiProxy.listen(this, position);
+ LOG.info("Listening for Box events again from position {}",
position != null ? position : "now");
+ } catch (Exception e) {
+ // such as Box still not reachable when the event stream starts
+ LOG.debug("Cannot listen for Box events again", e);
+ scheduleRestart();
Review Comment:
⚠️ **Silent retry on permanent failures:** `catch (Exception e)` is broad —
authentication failures (403, revoked credentials) are caught identically to
`IOException`/network errors. For all of them, `scheduleRestart()` retries
indefinitely (every 1–60 s), logging at DEBUG only.
The initial stream failure goes through `onException` →
`getExceptionHandler()` (WARN by default) — the user gets one warning. All
subsequent restart failures are invisible at the default log level. A user
whose credentials expire during an outage will see one WARN, then the consumer
silently retrying forever.
Consider logging at WARN or INFO when the caught exception is not an
`IOException` or Box network `BoxAPIException`, so permanent failures surface
at a visible level.
--
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]