Skip to content

Commit 3d57909

Browse files
Add time out when acquiring completionLock to avoid application stuck after ctrl-c (Azure#26379)
* Add time out when acquiring completionLock to avoid dead lock.
1 parent 3431bf5 commit 3d57909

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

sdk/servicebus/azure-messaging-servicebus/src/main/java/com/azure/messaging/servicebus/ServiceBusReceiverAsyncClient.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import java.util.Map;
3838
import java.util.Objects;
3939
import java.util.concurrent.Semaphore;
40+
import java.util.concurrent.TimeUnit;
4041
import java.util.concurrent.atomic.AtomicBoolean;
4142
import java.util.concurrent.atomic.AtomicLong;
4243
import java.util.concurrent.atomic.AtomicReference;
@@ -1199,7 +1200,12 @@ public void close() {
11991200
}
12001201

12011202
try {
1202-
completionLock.acquire();
1203+
// releated with issue https://github.com/Azure/azure-sdk-for-java/issues/25709. When defining ServiceBusProcessorClient as bean in SpringBoot application and throw error in processMessage(), the application can not be shutdown gracefully using ctrl-c.
1204+
// The cause is completionLock's acquire stucks. So we add a timeout for acquiring lock here to avoid the stuck.
1205+
boolean acquired = completionLock.tryAcquire(5, TimeUnit.SECONDS);
1206+
if (!acquired) {
1207+
logger.info("Unable to obtain completion lock.");
1208+
}
12031209
} catch (InterruptedException e) {
12041210
logger.info("Unable to obtain completion lock.", e);
12051211
}

0 commit comments

Comments
 (0)