apupier commented on code in PR #30711:
URL: https://github.com/apache/camel/pull/30711#discussion_r4681293788
##########
components/camel-ai/camel-semantic/src/main/java/org/apache/camel/semantic/SemanticEvaluateConsole.java:
##########
@@ -125,13 +153,37 @@ protected Map<String, Object> doCallJson(Map<String,
Object> options) {
SemanticAuditService.Request request
= audit.request(options.containsKey(OPERATION) ?
"direct_sample" : "definition_sample");
String failure;
+ AtomicBoolean claimed = new AtomicBoolean();
+ boolean acquired = false;
try {
long timeout = optionLong(options, TIMEOUT, 50000);
if (timeout < 1 || timeout > 50000) {
throw new IllegalArgumentException("Evaluation timeout must be
between 1 and 50000 milliseconds");
}
- task = executor().submit(() -> evaluate(options, request));
- return task.get(timeout, TimeUnit.MILLISECONDS);
+ long deadline = start + TimeUnit.MILLISECONDS.toNanos(timeout);
+ if (stopped || isStopping()) {
+ throw new IllegalStateException("Semantic evaluation console
is stopping or stopped");
+ }
+ if (!tryAcquire()) {
+ throw new RejectedExecutionException("Busy: semantic
evaluations are already running");
+ }
+ acquired = true;
+ ExecutorService exec = executor();
+ task = exec.submit(() -> {
+ if (System.nanoTime() > deadline ||
!claimed.compareAndSet(false, true)) {
+ return null;
Review Comment:
Addressed: when the worker starts after the deadline, it now throws within
its claim, which completes the future exceptionally with and cleans up the
slot in . The caller unwraps this and formats a proper response, avoiding
JSON responses or NPEs in text format. Added regression test in .
_IBM Bob on behalf of apupier_
--
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]