Repository navigation
perf(software): cap parallel Fleet calls at 8 per api pod - #2507
semen-flamingo wants to merge 1 commit into
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011SqwrRpyZt3bP1sWEUYr2P
🦩 Flamingo Code Review1 finding(s) — 1 action required · 0 recommended · 0 informational Mode: advisory · Rules cited: Inline comments: 1 new Need another pass? Commits pushed after this review are not reviewed automatically.
Prefer typing? Comment React 👍/👎 on inline comments to teach the reviewer. Started 2026-10-01 14:28 UTC · updated 2026-10-01 14:30 UTC · workflow run |
| private static <T, R> R limited(Function<T, R> call, T key) throws InterruptedException { | ||
| IN_FLIGHT.acquire(); | ||
| try { | ||
| return call.apply(key); | ||
| } finally { | ||
| IN_FLIGHT.release(); | ||
| } | ||
| } |
There was a problem hiding this comment.
🦩 🔴 [error/action_required] OFJAVA-014 limited() declares a checked throws InterruptedException, violating the unchecked-exceptions rule and losing the interrupt status
The new private method limited is declared throws InterruptedException, a checked exception. Per OFJAVA-014 all exceptions in this codebase must be unchecked, with no throws clauses in signatures. Worse, because this call runs inside executor.submit(() -> limited(call, key)), the InterruptedException is captured by the Future and only surfaces later through resultOf, which only special-cases RuntimeException — an InterruptedException thrown by IN_FLIGHT.acquire() is not a RuntimeException, so future.resultNow() will throw IllegalStateException (wrong state) instead of propagating the real cause, and the thread's interrupt status is silently lost (never re-set with Thread.currentThread().interrupt()). This can turn a shutdown/interrupt signal into a confusing IllegalStateException, and defeats cooperative cancellation of the virtual-thread pool.
Evidence
private static <T, R> R limited(Function<T, R> call, T key) throws InterruptedException {
IN_FLIGHT.acquire();
try {
return call.apply(key);
} finally {
IN_FLIGHT.release();
}
}
📝 Committable suggestion
| private static <T, R> R limited(Function<T, R> call, T key) throws InterruptedException { | |
| IN_FLIGHT.acquire(); | |
| try { | |
| return call.apply(key); | |
| } finally { | |
| IN_FLIGHT.release(); | |
| } | |
| } | |
| private static <T, R> R limited(Function<T, R> call, T key) { | |
| try { | |
| IN_FLIGHT.acquire(); | |
| } catch (InterruptedException e) { | |
| Thread.currentThread().interrupt(); | |
| throw new IllegalStateException("interrupted while waiting for Fleet call slot", e); | |
| } | |
| try { | |
| return call.apply(key); | |
| } finally { | |
| IN_FLIGHT.release(); | |
| } | |
| } |
🤖 Prompt for AI agents
In openframe-api-lib/src/main/java/com/openframe/api/service/rmm/fleet/FleetCalls.java around lines 31-38, address this code-review finding: limited() declares a checked throws InterruptedException, violating the unchecked-exceptions rule and losing the interrupt status.
The new private method `limited` is declared `throws InterruptedException`, a checked exception. Per OFJAVA-014 all exceptions in this codebase must be unchecked, with no `throws` clauses in signatures. Worse, because this call runs inside `executor.submit(() -> limited(call, key))`, the InterruptedException is captured by the Future and only surfaces later through `resultOf`, which only special-cases RuntimeException — an InterruptedException thrown by `IN_FLIGHT.acquire()` is not a RuntimeException, so `future.resultNow()` will throw `IllegalStateException` (wrong state) instead of propagating the real cause, and the thread's interrupt status is silently lost (never re-set with `Thread.currentThread().interrupt()`). This can turn a shutdown/interrupt signal into a confusing IllegalStateException, and defeats cooperative cancellation of the virtual-thread pool.
The flagged code:
```
private static <T, R> R limited(Function<T, R> call, T key) throws InterruptedException {
IN_FLIGHT.acquire();
try {
return call.apply(key);
} finally {
IN_FLIGHT.release();
}
}
```
A suggested replacement for the flagged range:
private static <T, R> R limited(Function<T, R> call, T key) {
try {
IN_FLIGHT.acquire();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new IllegalStateException("interrupted while waiting for Fleet call slot", e);
}
try {
return call.apply(key);
} finally {
IN_FLIGHT.release();
}
}
Make the minimal change that resolves the finding; do not refactor unrelated code.
confidence: verifier 75 · author 78 — react 👍/👎 to teach the reviewer
|
Closing as stale: no activity for over a week. Reopen if still needed. |
What
With
openframe.rmm.software.fleet-paging.enabledon (#2484), a few Software Management tabs call Fleet in parallel: one call per software version, or one per row on the page.One Fleet serves every tenant and their agents. On prod it has 1 CPU and a shared MySQL pool. One click on a title with many versions could send it ~40–80 calls at once.
FleetCallsnow lets at most 8 Fleet calls run at a time per api pod; the rest queue. The cap is shared across requests, so several users clicking at once still stay under 8. Results keep their order, and a failing call still throws its own exception.Measured on QA: versions per software title have a median of 1, p90 of 4, p99 of 9 and a max of 38 (AdGuard). The worst case becomes 5 waves of ~0.1–0.3 s.
Fleet calls per screen, before and after #2484
QA numbers:
The "snapshot" means
⌈hosts/100⌉calls to/hosts?populate_software=true. Each call returns 100 hosts with all their software. The snapshot is cached for 2 min per pod, and it is what runs prod api pods out of heap.The two device tabs make more calls than before. But each call is a light lookup of one title or one CVE, while before the tab built or reused the snapshot of every host's software.
Tests
FleetCallsTest: 30 calls never exceed 8 in flight, results keep key order, and the failing call's exception is rethrown.🤖 Generated with Claude Code
https://claude.ai/code/session_011SqwrRpyZt3bP1sWEUYr2P