You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by "allthingssecurity (via GitHub)" <gi...@apache.org> on 2026/10/17 00:11:32 UTC
[PR] CAMEL-25701: camel-azure-servicebus - renew a message lock before the run that would come too late [camel]
allthingssecurity opened a new pull request, #27986:
URL: https://github.com/apache/camel/pull/27986
# Description
[CAMEL-25701](https://issues.apache.org/jira/browse/CAMEL-25701)
Since CAMEL-23937 the Service Bus consumer renews message locks itself in `PEEK_LOCK` mode (the default, with the default `maxAutoLockRenewDuration` of 5 minutes, sessions disabled), because the SDK stops renewing when Camel's callback returns, which is immediately for an asynchronous route. The `LockRenewer` is scheduled with `PeriodTaskScheduler.schedulePeriodTask(lockRenewer, 10000)` and renewed a lock when it expired within `LOCK_RENEW_INTERVAL_SECONDS` (10 seconds).
The period task scheduler ticks once per second and runs the task when more than 10000 ms have passed since its last run, so two runs are 10 or 11 seconds apart, while the window in which the renewer acted was 10 seconds long. A lock that expired between 10 and 11 seconds after a run was left alone by that run, and the next run came after the expiry, or too close to it for the renewal call. The renewal then failed with a lost lock ("Failed to renew lock" WARN, entry dropped), Service Bus delivered the message again while the first exchange was still being processed, and the final `complete()` of that exchange failed.
A small exhaustive timing model (every sequence of 6 run gaps of 10 or 11 seconds, lock expiry at every 100 ms phase) loses the lock in 6.0% of the lock periods with the 10-second margin (11% when every gap is 11 seconds) and in none with a margin of two intervals.
Change (`ServiceBusConsumer.LockRenewer.run()`, one line plus comment): renew when the lock expires within `2 * LOCK_RENEW_INTERVAL_SECONDS`. Every lock is then renewed by a run that comes at least about 9 seconds before it expires.
What users can notice: long-running exchanges of asynchronous routes keep their lock instead of losing it now and then. Locks are renewed somewhat earlier (about once per lock duration, as before; at every run when the lock duration is 20 seconds or less). No option or default changes, so no upgrade guide entry.
Tests (in `ServiceBusConsumerTest`, Mockito, no Service Bus, no waits):
- `lockRenewerRenewsALockThatWouldExpireBeforeItsNextRun`: the renewer is captured from the scheduler with its period; a message whose lock expires 2 seconds after the earliest possible next run is tracked and the renewer runs once; it must renew. Fails without the change: `Wanted but not invoked: renewalClient.renewMessageLock(message)`.
- `lockRenewerDoesNotRenewALockThatOutlastsTheNextRuns`: a lock that expires in 60 seconds is not renewed. Passes without the change too; it guards against renewing too early.
- With the change the camel-azure-servicebus unit tests pass: 79 run, 0 failures, 8 skipped (the integration tests that need a Service Bus namespace).
What is not changed:
- The renewal is still issued without waiting for the previous one; a renewal that takes longer than an interval is not tracked.
- Session-enabled consumers still have no Camel-managed renewal (CAMEL-23938).
- The renewer of a stopped consumer stays registered (cancelled) in the period task scheduler until the CamelContext stops.
What was not run: the integration tests, a real namespace with long-running exchanges.
# Target
- [x] I checked that the commit is targeting the correct branch (Camel 4 uses the `main` branch)
# Tracking
- [x] If this is a large change, bug fix, or code improvement, I checked there is a [JIRA issue](https://issues.apache.org/jira/browse/CAMEL) filed for the change (usually before you start working on it): [CAMEL-25701](https://issues.apache.org/jira/browse/CAMEL-25701).
# Apache Camel coding standards and style
- [x] I checked that each commit in the pull request has a meaningful subject line and body.
- [ ] I have run `mvn clean install -DskipTests` locally from root folder and I have committed all auto-generated changes.
(I built and tested camel-azure-servicebus, including the formatter and import-sort plugins. I did not run the full root build.)
# AI-assisted contributions
- [x] If this PR includes AI-generated code, commits have proper co-authorship attribution (e.g., `Co-authored-by` trailers) and the PR description identifies the AI tool used.
This PR was prepared with Claude Code (Claude Opus 5.5). The commit carries a `Co-Authored-By` trailer.
_Claude Code on behalf of allthingssecurity_
🤖 Generated with [Claude Code](https://claude.com/claude-code)
--
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: commits-unsubscribe@camel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] CAMEL-25701: camel-azure-servicebus - renew a message lock before the run that would come too late [camel]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #27986:
URL: https://github.com/apache/camel/pull/27986#issuecomment-6230665564
:star2: Thank you for your contribution to the Apache Camel project! :star2:
:robot: CI automation will test this PR automatically.
:camel: Apache Camel Committers, please review the following items:
* First-time contributors **require MANUAL approval** for the GitHub Actions to run
* You can use the command `/component-test (camel-)component-name1 (camel-)component-name2..` to request a test from the test bot although they are normally detected and executed by CI.
* You can label PRs using `skip-tests` and `test-dependents` to fine-tune the checks executed by this PR.
* Build and test logs are available in the summary page. **Only** [Apache Camel committers](https://camel.apache.org/community/team/#committers) have access to the summary.
:warning: Be careful when sharing logs. Review their contents before sharing them publicly.
--
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: commits-unsubscribe@camel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] CAMEL-25701: camel-azure-servicebus - renew a message lock before the run that would come too late [camel]
Posted by "davsclaus (via GitHub)" <gi...@apache.org>.
davsclaus merged PR #27986:
URL: https://github.com/apache/camel/pull/27986
--
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: commits-unsubscribe@camel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] CAMEL-25701: camel-azure-servicebus - renew a message lock before the run that would come too late [camel]
Posted by "allthingssecurity (via GitHub)" <gi...@apache.org>.
allthingssecurity commented on code in PR #27986:
URL: https://github.com/apache/camel/pull/27986#discussion_r4301872986
##########
components/camel-azure/camel-azure-servicebus/src/main/java/org/apache/camel/component/azure/servicebus/ServiceBusConsumer.java:
##########
@@ -342,9 +342,11 @@ public void run() {
continue;
}
- // renew if lock is approaching expiry
+ // renew if the lock expires before the run after the next one: the period task scheduler runs this
+ // task every LOCK_RENEW_INTERVAL_SECONDS or a second later, so waiting for the next run when the lock
+ // expires within one interval can be too late, and the renewal itself is a call to Service Bus
Instant lockExpiry = entry.lockedUntil.toInstant();
- if (now.plusSeconds(LOCK_RENEW_INTERVAL_SECONDS).isAfter(lockExpiry)) {
+ if (now.plusSeconds(2L * LOCK_RENEW_INTERVAL_SECONDS).isAfter(lockExpiry)) {
Review Comment:
Thanks for checking. Agreed that short lock durations are a separate limit. With a 5 s lock and a renewer that runs every 10 to 11 s, the lock cannot be kept whatever the window is. I have noted it as a follow-up (run the renewer every 1 to 2 s, with the window scaled to the period) and kept this PR as it is.
_Claude Code on behalf of allthingssecurity_
--
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: commits-unsubscribe@camel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] CAMEL-25701: camel-azure-servicebus - renew a message lock before the run that would come too late [camel]
Posted by "davsclaus (via GitHub)" <gi...@apache.org>.
davsclaus commented on code in PR #27986:
URL: https://github.com/apache/camel/pull/27986#discussion_r4301785982
##########
components/camel-azure/camel-azure-servicebus/src/main/java/org/apache/camel/component/azure/servicebus/ServiceBusConsumer.java:
##########
@@ -342,9 +342,11 @@ public void run() {
continue;
}
- // renew if lock is approaching expiry
+ // renew if the lock expires before the run after the next one: the period task scheduler runs this
+ // task every LOCK_RENEW_INTERVAL_SECONDS or a second later, so waiting for the next run when the lock
+ // expires within one interval can be too late, and the renewal itself is a call to Service Bus
Instant lockExpiry = entry.lockedUntil.toInstant();
- if (now.plusSeconds(LOCK_RENEW_INTERVAL_SECONDS).isAfter(lockExpiry)) {
+ if (now.plusSeconds(2L * LOCK_RENEW_INTERVAL_SECONDS).isAfter(lockExpiry)) {
Review Comment:
Fine as is. A related limit for a possible follow-up, which this change does not cause: Service Bus allows a lock duration as short as 5 seconds. With the renewer running only every 10 to 11 seconds, locks of about 11 seconds or less still cannot be kept, because each renewal only extends the lock by its own duration. Running the renewer more often (for example every 1 to 2 seconds, with the window scaled to the period) would cover short lock durations too. It costs little, since a run only calls Service Bus for the locks that are close to expiry.
--
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: commits-unsubscribe@camel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] CAMEL-25701: camel-azure-servicebus - renew a message lock before the run that would come too late [camel]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #27986:
URL: https://github.com/apache/camel/pull/27986#issuecomment-6230971410
<!-- ci-tested-modules -->
:test_tube: **CI tested the following changed modules:**
- `components/camel-azure/camel-azure-servicebus`
:repeat: **1 test passed only after a retry on JDK 17** (1 retried attempt)
<details><summary>Recovered flaky tests on JDK 17 (1)</summary>
| Module | Test | Failed attempts | First failure |
| --- | --- | --- | --- |
| `dsl/camel-jbang/camel-jbang-plugin-tui` | `LaunchManagerOutcomeTest.startedWhenTheStatusFileSaysSo` | 1 | expected: null but was: LaunchOutcome[ok=false, log=null] |
> :information_source: These tests did **not** fail the build. Surefire retried them and they passed.
> Retries are enabled project-wide by `surefire.rerunFailingTestsCount` in `parent/pom.xml`.
</details>
---
<details><summary>:microscope: Scalpel shadow comparison — Scalpel: 8 of 706 tested, 27 compile-only — current: 8 all tested</summary>
[Maveniverse Scalpel](https://github.com/maveniverse/scalpel) detected **8 affected modules** (current approach: 8).
**Skip-tests mode would test 8 modules** (1 direct + 7 downstream), **skip tests for 27** (generated code, meta-modules)
<details><summary>Modules Scalpel would test (8)</summary>
- `camel-azure-servicebus` ← components/camel-azure/camel-azure-servicebus/src/main/java/org/apache/camel/component/azure/servicebus/ServiceBusConsumer.java, components/camel-azure/camel-azure-servicebus/src/test/java/org/apache/camel/component/azure/servicebus/ServiceBusConsumerTest.java
- `camel-jbang-mcp` ← downstream of org.apache.camel:camel-catalog
- `camel-jbang-plugin-mcp` ← downstream of org.apache.camel:camel-jbang-core
- `camel-jbang-plugin-tui` ← downstream of org.apache.camel:camel-catalog
- `camel-jbang-plugin-validate` ← downstream of org.apache.camel:camel-yaml-dsl-validator
- `camel-launcher-container` ← downstream of org.apache.camel:camel-launcher
- `camel-yaml-dsl-validator` ← downstream of org.apache.camel:camel-catalog
- `camel-yaml-dsl-validator-maven-plugin` ← downstream of org.apache.camel:camel-yaml-dsl-validator
</details>
<details><summary>Modules with tests skipped (27)</summary>
- `apache-camel`
- `camel-allcomponents`
- `camel-catalog`
- `camel-catalog-console`
- `camel-catalog-maven`
- `camel-catalog-suggest`
- `camel-componentdsl`
- `camel-endpointdsl`
- `camel-endpointdsl-support`
- `camel-itest`
- `camel-jbang-core`
- `camel-jbang-it`
- `camel-jbang-main`
- `camel-jbang-plugin-edit`
- `camel-jbang-plugin-generate`
- `camel-jbang-plugin-kubernetes`
- `camel-jbang-plugin-test`
- `camel-kamelet-main`
- `camel-launcher`
- `camel-report-maven-plugin`
- `camel-route-parser`
- `camel-yaml-dsl`
- `camel-yaml-dsl-deserializers`
- `camel-yaml-dsl-maven-plugin`
- `coverage`
- `docs`
- `dummy-component`
</details>
> :information_source: Shadow mode — Scalpel observes but does not affect test execution. [Learn more](https://github.com/maveniverse/scalpel)
</details>
<details><summary>All tested modules (35 modules, 6m 8s total)</summary>
**Total reactor time:** 6m 8s
| Module | Duration | Status |
| --- | --- | --- |
| Camel :: Launcher | 54.2s | SUCCESS |
| Camel :: JBang :: MCP | 47.4s | SUCCESS |
| Camel :: JBang :: Plugin :: Validate | 35.8s | SUCCESS |
| Camel :: Catalog :: Camel Catalog | 25.4s | SUCCESS |
| Camel :: YAML DSL :: Validator | 24.0s | SUCCESS |
| Camel :: YAML DSL | 21.6s | SUCCESS |
| Camel :: Component DSL | 20.1s | SUCCESS |
| Camel :: Azure :: ServiceBus | 16.3s | SUCCESS |
| Camel :: Docs | 16.2s | SUCCESS |
| Camel :: JBang :: Plugin :: Kubernetes | 15.4s | SUCCESS |
| Camel :: JBang :: Plugin :: Testing | 14.7s | SUCCESS |
| Camel :: Catalog :: Camel Report Maven Plugin | 13.7s | SUCCESS |
| Camel :: Kamelet Main | 13.5s | SUCCESS |
| Camel :: Catalog :: Camel Route Parser | 8.7s | SUCCESS |
| Camel :: YAML DSL :: Deserializers | 8.7s | SUCCESS |
| Camel :: All Components Sync point | 5.8s | SUCCESS |
| Camel :: YAML DSL :: Validator Maven Plugin | 5.0s | SUCCESS |
| Camel :: YAML DSL :: Maven Plugins | 3.7s | SUCCESS |
| Camel :: Catalog :: Maven | 3.6s | SUCCESS |
| Camel :: Assembly | 2.4s | SUCCESS |
| Camel :: Catalog :: Suggest (deprecated) | 1.9s | SUCCESS |
| Camel :: JBang :: Plugin :: Edit | 1.5s | SUCCESS |
| Camel :: Coverage | 1.2s | SUCCESS |
| Camel :: Catalog :: Dummy Component | 1.1s | SUCCESS |
| Camel :: JBang :: Plugin :: Generate | 1.1s | SUCCESS |
| Camel :: JBang :: Integration tests | 1.0s | SUCCESS |
| Camel :: Catalog :: Console | 0.9s | SUCCESS |
| Camel :: JBang :: Plugin :: MCP | 0.9s | SUCCESS |
| Camel :: Launcher :: Container | 0.7s | SUCCESS |
| Camel :: JBang :: Main | 0.7s | SUCCESS |
| Camel :: Endpoint DSL :: Support | 0.7s | SUCCESS |
| Camel :: Endpoint DSL | n/a | |
| Camel :: Integration Tests | n/a | |
| Camel :: JBang :: Core | n/a | |
| Camel :: JBang :: Plugin :: TUI | n/a | |
**Top 20 slowest modules:**
- `Camel :: Launcher` (54.2s)
- `Camel :: JBang :: MCP` (47.4s)
- `Camel :: JBang :: Plugin :: Validate` (35.8s)
- `Camel :: Catalog :: Camel Catalog` (25.4s)
- `Camel :: YAML DSL :: Validator` (24.0s)
- `Camel :: YAML DSL` (21.6s)
- `Camel :: Component DSL` (20.1s)
- `Camel :: Azure :: ServiceBus` (16.3s)
- `Camel :: Docs` (16.2s)
- `Camel :: JBang :: Plugin :: Kubernetes` (15.4s)
- `Camel :: JBang :: Plugin :: Testing` (14.7s)
- `Camel :: Catalog :: Camel Report Maven Plugin` (13.7s)
- `Camel :: Kamelet Main` (13.5s)
- `Camel :: Catalog :: Camel Route Parser` (8.7s)
- `Camel :: YAML DSL :: Deserializers` (8.7s)
- `Camel :: All Components Sync point` (5.8s)
- `Camel :: YAML DSL :: Validator Maven Plugin` (5.0s)
- `Camel :: YAML DSL :: Maven Plugins` (3.7s)
- `Camel :: Catalog :: Maven` (3.6s)
- `Camel :: Assembly` (2.4s)
</details>
---
:gear: [View full build and test results](https://github.com/apache/camel/actions/runs/38985212031)
--
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: commits-unsubscribe@camel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org