Croway opened a new pull request, #24805:
URL: https://github.com/apache/camel/pull/24805

   ## Summary
   
   `AbstractCamelContext.doGetEndpoint()` normalizes the uri once for its cache 
lookup (`NormalizedUri.newNormalizedUri(uri, true)` - "already normalized"), 
but on a cache miss it handed that *already normalized* uri to 
`addEndpointToRegistry()`, which called `getEndpointKey(uri, endpoint)` -> 
`NormalizedUri.newNormalizedUri(uri, false)` - "not normalized yet, please 
normalize it" - re-running `EndpointHelper.normalizeEndpointUri()` a **second** 
time before storing the registry key.
   
   `EndpointHelper.normalizeEndpointUri()` (via `URISupport.normalizeUri` / 
`UnsafeUriCharactersEncoder`) is not idempotent for any uri containing a 
literal `%`: it encodes it to `%25` on every pass, so a second pass turns `%41` 
into `%2541`. Because the *stored* key ends up double-normalized while the 
*lookup* key computed fresh on a later call is only single-normalized, they 
never match again - `CamelContext#getEndpoint(String)` creates and starts a 
**brand-new** `Endpoint` on every single call for any uri containing a `%`, 
instead of reusing the cached singleton.
   
   - Fixes CAMEL-24187
   - Discovered while investigating CAMEL-24171: camel-plc4x S7 tag addresses 
conventionally contain a literal `%` (e.g. `RAW(%DB1.DBX0.0:BOOL)`), unlike 
Modbus' (`RAW(coil:1)`), which is why only the S7 route reloaded its 
`DefaultPlcDriverManager` on every poll while the structurally identical Modbus 
route did not. camel-plc4x itself is not at fault - the same symptom applies to 
any component whose endpoint uri legitimately contains a `%` and is re-resolved 
by string on every use, as `pollEnrich`/`toD`/`recipientList` do.
   
   ## Fix
   
   Added a `normalized`-aware overload of 
`getEndpointKey()`/`addEndpointToRegistry()` so only the `doGetEndpoint()` call 
site (whose uri is provably already normalized) skips the redundant second 
normalization pass. The public `hasEndpoint(String)`, `addEndpoint(String, 
Endpoint)` and `removeEndpoints(String)` APIs still receive raw, 
caller-supplied uris directly and keep normalizing exactly as before - flipping 
the existing method wholesale would have silently broken those three call sites.
   
   ## Test plan
   
   - [x] New camel-core test 
`DefaultEndpointRegistryTest#testGetEndpointIsCachedForUriContainingPercentCharacter`
 isolates the bug with no plc4x involvement 
(`controlbus:route?routeId=RAW(%41)&action=status` resolved twice returns two 
different instances before the fix, the same instance after).
   - [x] New camel-plc4x test `Plc4XPollEnrichDoStartReproducerTest` reproduces 
the real-world consequence: with the fix, both a S7-shaped and a Modbus-shaped 
`pollEnrich` route only start their `Plc4XEndpoint` once, no matter how many 
poll cycles run.
   - [x] Full `camel-core` test suite run locally with the fix: 7300 tests, 18 
failures / 3 errors - all individually verified to fail identically with the 
fix reverted (pre-existing on `origin/main`, unrelated to this change). Zero 
regressions introduced.
   
   ---
   
   _Claude Sonnet 5 on behalf of Croway_


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