Skip to content

Commit 1acafa3

Browse files
authored
Ensure shutdown of LA slot queue isn't swallowed (#2161)
1 parent e5c08a1 commit 1acafa3

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

temporal-sdk/src/main/java/io/temporal/internal/worker/LocalActivitySlotSupplierQueue.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ private void processQueue() {
8484
SlotPermit slotPermit;
8585
try {
8686
slotPermit = slotSupplier.reserveSlot(request.data);
87+
} catch (InterruptedException e) {
88+
Thread.currentThread().interrupt();
89+
return;
8790
} catch (Exception e) {
8891
log.error(
8992
"Error reserving local activity slot, dropped activity id {}",
@@ -131,8 +134,4 @@ void submitAttempt(SlotReservationData data, boolean isRetry, LocalActivityAttem
131134
newExecutionsBackpressureSemaphore.release();
132135
}
133136
}
134-
135-
TrackingSlotSupplier<LocalActivitySlotInfo> getSlotSupplier() {
136-
return slotSupplier;
137-
}
138137
}

temporal-sdk/src/main/java/io/temporal/internal/worker/LocalActivityWorker.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -717,6 +717,7 @@ public CompletableFuture<Void> shutdown(ShutdownManager shutdownManager, boolean
717717

718718
@Override
719719
public void awaitTermination(long timeout, TimeUnit unit) {
720+
slotQueue.shutdown();
720721
long timeoutMillis = unit.toMillis(timeout);
721722
ShutdownManager.awaitTermination(scheduledExecutor, timeoutMillis);
722723
}

temporal-sdk/src/test/java/io/temporal/internal/worker/WorkflowSlotsSmallSizeTests.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import java.util.List;
4848
import java.util.Map;
4949
import java.util.concurrent.Semaphore;
50+
import java.util.concurrent.TimeUnit;
5051
import org.junit.After;
5152
import org.junit.Before;
5253
import org.junit.Rule;
@@ -249,6 +250,29 @@ public void TestLocalActivitySlotAtLimit() throws InterruptedException {
249250
MAX_CONCURRENT_LOCAL_ACTIVITY_EXECUTION_SIZE);
250251
}
251252

253+
@Test
254+
public void TestLocalActivityShutdownWhileWaitingOnSlot() throws InterruptedException {
255+
testWorkflowRule.getTestEnvironment().start();
256+
WorkflowClient client = testWorkflowRule.getWorkflowClient();
257+
TestWorkflow workflow =
258+
client.newWorkflowStub(
259+
TestWorkflow.class,
260+
WorkflowOptions.newBuilder()
261+
.setTaskQueue(testWorkflowRule.getTaskQueue())
262+
.validateBuildWithDefaults());
263+
WorkflowClient.start(workflow::workflow, activitiesAreLocal);
264+
workflow.unblock();
265+
parallelSemRunning.acquire(2);
266+
testWorkflowRule.getTestEnvironment().getWorkerFactory().shutdownNow();
267+
parallelSemBlocked.release(2);
268+
testWorkflowRule.getTestEnvironment().getWorkerFactory().awaitTermination(3, TimeUnit.SECONDS);
269+
// All slots should be available
270+
assertWorkerSlotCount(
271+
MAX_CONCURRENT_WORKFLOW_TASK_EXECUTION_SIZE,
272+
MAX_CONCURRENT_ACTIVITY_EXECUTION_SIZE,
273+
MAX_CONCURRENT_LOCAL_ACTIVITY_EXECUTION_SIZE);
274+
}
275+
252276
@Test
253277
public void TestLocalActivitySlotHitsCapacity() throws InterruptedException {
254278
testWorkflowRule.getTestEnvironment().start();

0 commit comments

Comments
 (0)