Dhairya-007 opened a new pull request, #29677:
URL: https://github.com/apache/camel/pull/29677
## Problem
`MessageReceiverListenerImpl` waits on a latch at the top of all three
`onAccept*` methods, because in `messageReceiverRouteId` mode the `consumer`,
`processor` and `exceptionHandler` fields are only assigned later, by a
`StartupListener`:
```java
try {
// wait for initialization in case consumer is active before startup
listener above has been executed
initialized.await(10, TimeUnit.SECONDS);
} catch (InterruptedException e) {
// ignore
}
LOG.debug("Received a deliverSm {}", deliverSm);
...
processor.process(exchange);
```
`CountDownLatch.await(timeout, unit)` returns a `boolean`, and the result is
dropped. If the latch has not counted down within ten seconds, or the receiving
thread is interrupted, execution falls through to
`createOnAcceptDeliverSmExchange(...)` and `processor.process(...)` with those
fields still `null`. The SMSC then sees a `NullPointerException` out of the
listener rather than a protocol-level failure, and for `deliver_sm`/`data_sm`
the real cause — that the route was not ready — is nowhere in the message.
Swallowing the `InterruptedException` also drops the interrupt flag, so a
consumer being shut down keeps waiting the full timeout on every subsequent
message.
## Fix
Move the wait into `awaitInitialization()`, which
- returns the result of the bounded `await`, and
- calls `Thread.currentThread().interrupt()` before returning `false` on
interruption.
When it returns `false`:
- `onAcceptDeliverSm` / `onAcceptDataSm` throw `ProcessRequestException` —
the way this class already reports a failure to the SMSC — with the error code
255 the existing fallback uses;
- `onAcceptAlertNotification` logs a warning and returns, since an alert
notification has no response.
## Tests
`MessageReceiverListenerImplTest.aMessageArrivingBeforeInitializationIsRejected`
builds the listener against a context that is never started, so the
`StartupListener` never runs and the latch is never released. It interrupts the
calling thread so the bounded wait returns at once instead of taking the full
ten seconds, then asserts that `onAcceptDeliverSm` throws
`ProcessRequestException` and that the interrupt flag was restored. On `main`
the same test fails with a `NullPointerException`.
--
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]