Skip to content

Commit

Permalink
OK-611 Fiksattu permittien vapauttamisbugi
Browse files Browse the repository at this point in the history
  • Loading branch information
jkorri committed Dec 3, 2024
1 parent 3850a0b commit 2180021
Showing 1 changed file with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,16 +123,30 @@ public <T> CompletableFuture<T> withConcurrencyLimit(

Instant waitStart = Instant.now();
CompletableFuture<T> future = new CompletableFuture<>();
int requiredPermits = Math.min(this.maxPermits, permits);

this.executor.submit(
() -> {
// haetaan lupa suorittaa pyyntö ja tallennetaan odottamiseen mennyt aika
this.waiting.incrementAndGet();
try {
this.semaphore.acquireUninterruptibly(Math.min(this.maxPermits, permits));
this.semaphore.acquireUninterruptibly(requiredPermits);
} finally {
this.waiting.decrementAndGet();
}

if (nimi.equals("suoritukset")) {
LOG.info(
"Haettiin "
+ permits
+ " permittiä, jäi "
+ this.semaphore.availablePermits()
+ " permittiä, ajossa "
+ this.getActive()
+ ", odottaa "
+ this.getWaiting());
}

Instant invokeStart = Instant.now();
waitDurations.put(this.nimi, Duration.between(waitStart, invokeStart));

Expand All @@ -156,7 +170,7 @@ public <T> CompletableFuture<T> withConcurrencyLimit(
invokeDurations.put(this.nimi, ERROR);
future.completeExceptionally(e);
} finally {
semaphore.release(permits);
semaphore.release(requiredPermits);
this.active.decrementAndGet();
}
});
Expand Down

0 comments on commit 2180021

Please sign in to comment.