gnodet-bot commented on code in PR #30390:
URL: https://github.com/apache/camel/pull/30390#discussion_r4627250165
##########
components/camel-opa/src/test/java/org/apache/camel/component/opa/OpaReloadableWasmEvaluatorTest.java:
##########
@@ -269,6 +270,52 @@ void managedWatcherDoesNotBuildTheSameFailedContentAgain()
throws Exception {
}
}
+ @Test
+ void
pollingSkipsUnchangedMalformedDataButExplicitReloadRetriesAndChangedContentRecovers()
throws Exception {
Review Comment:
⚠️ **Test coverage gap:** this test validates the `skipKnownFailure`
scheduling contract — polling skips unchanged malformed content, explicit
reload retries, valid content recovers — which is valuable. However, it does
**not** exercise the buffer-ownership race that the `.clone()` on line 146 of
`OpaReloadableWasmEvaluator` fixes.
The loader here returns `content.get()`, which always yields the same
`Bundle` reference with a `new byte[]{2}` that is never mutated between
`load()` and `revision()`. The race fixed by `.clone()` requires a loader whose
internal `byte[]` is overwritten between successive calls — this test has no
such mutation.
Consider adding a targeted test with a buffer-reusing loader: return the
same `byte[]` instance, mutate it after `load()` returns, and assert that the
revision computed in one poll is not poisoned by a concurrent mutation.
##########
components/camel-opa/src/main/java/org/apache/camel/component/opa/OpaReloadableWasmEvaluator.java:
##########
@@ -161,6 +161,7 @@ private boolean reload(long generation, boolean
skipKnownFailure) throws Excepti
return false;
}
}
+ OpaWasmEvaluator.Bundle bundle = immutableBundle(loaded);
Review Comment:
💡 **Redundant clone:** after line 146 (`loaded.wasm().clone()`), `reload()`
owns the only reference to the cloned byte array — the original loader buffer
was not retained. When `immutableBundle(loaded)` runs here, it clones `wasm` a
second time (`return new OpaWasmEvaluator.Bundle(bundle.wasm().clone(),
bundle.data())`), doubling the allocation for every reload. Since `loaded` is
already an exclusive snapshot, the second clone is redundant on this path.
Consider calling `factory.create(loaded)` directly after inline validation,
or documenting that `immutableBundle()` assumes shared ownership so callers
must clone first.
--
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]