Repository navigation
Description
Describe the bug
ServiceBusSenderClient.sendMessage() becomes permanently stuck (until JVM restart) when a single AMQP sender link is silently detached (e.g. by LB/NAT idle timeout on Kubernetes). The dead link is cached in ReactorSession.openSendLinks and returned on every subsequent call without any liveness check. RetryUtil.withRetry() re-subscribes to the same Mono chain, reacquiring the same dead link on every retry, causing all attempts to hang identically until the 245.6-second retry budget is exhausted.
Key observation: This is a per-entity (per-queue) failure, not a per-connection failure. Other queues on the same AMQP connection continue to work normally because openSendLinks is keyed by entity path. This makes the issue particularly difficult to diagnose — the connection appears healthy.
Exception or Stack Trace
java.lang.IllegalStateException: Timeout on blocking read for 245600000000 NANOSECONDS
at reactor.core.publisher.BlockingSingleSubscriber.blockingGet(BlockingSingleSubscriber.java:123)
at reactor.core.publisher.Mono.block(Mono.java:1742)
at com.azure.messaging.servicebus.ServiceBusSenderClient.sendMessage(ServiceBusSenderClient.java:XXX)
245.6s = tryTimeout(60s) × 4 attempts + exponential backoff (0.8 + 1.6 + 3.2)s — this matches the default AmqpRetryOptions budget exactly.
To Reproduce
- Deploy a Spring Boot application on Kubernetes (AKS) using
ServiceBusSenderClient(sync) to send to multiple Service Bus queues via a singleServiceBusClientBuilder(shared connection) - Wait for an idle period where one queue's sender link is silently detached by infrastructure (LB idle timeout, NAT state eviction, etc.)
- Send a message to the affected queue → hangs for 245.6s →
TimeoutException - Send a message to a different queue on the same connection → succeeds in ~20ms
- Repeat step 3 → same hang, indefinitely, until JVM restart
Code Snippet
// Configuration — single builder, multiple senders sharing one connection
@Bean
public ServiceBusClientBuilder serviceBusClientBuilder() {
return new ServiceBusClientBuilder()
.connectionString(connectionString);
// Note: no retryOptions specified → defaults apply
}
@Bean
public ServiceBusSenderClient previewSender(ServiceBusClientBuilder builder) {
return builder.sender().queueName("queue-a").buildClient(); // This one gets stuck
}
@Bean
public ServiceBusSenderClient audioSender(ServiceBusClientBuilder builder) {
return builder.sender().queueName("queue-b").buildClient(); // This one keeps working
}
// Usage — identical message, different queues
public void sendPreview(ServiceBusMessage msg) {
previewSender.sendMessage(msg); // Hangs 245.6s → TimeoutException (100% failure)
}
public void sendAudio(ServiceBusMessage msg) {
audioSender.sendMessage(msg); // Succeeds in ~20ms (100% success)
}Expected behavior
When a sender link is detached, the SDK should detect the stale link and recreate it — either proactively (liveness check on cache hit) or reactively (between retry attempts). This is what Go, .NET, Python, and JS SDKs all do. The sender should recover without requiring a JVM restart.
Evidence from production incident
| Evidence | Detail |
|---|---|
| Same connection, different outcome | Pod A: queue-b send OK (12–33ms), queue-a send hang (245.6s). Same JVM, same connection (ConnectionImpl count = 1 in heap histogram) |
| Different pod, same queue | Pod B (fresh JVM): queue-a send OK (87.8ms) at the exact same time Pod A was failing → Azure service confirmed healthy |
| Failure rate | Pod A: 10/10 attempts failed over 25 hours. 0/10 recovered. Only fix was pod restart |
| Azure metrics | ServerErrors, UserErrors, ThrottledRequests = 0 across the entire period. Queue status = Active, message count = 0 |
| OTel spans | Pod A's queue-a send spans never completed (no success or failure recorded). Pod A's queue-b send spans completed normally |
| Heap histogram | ConnectionImpl: 1, ReactorSender: 2 (one live for queue-b, one stale for queue-a), ServiceBusSenderClient: 16 |
Root cause in SDK source
Two code locations combine to create the permanent stuck state:
1. ReactorSession.java:467 — stale link returned from cache without liveness check:
final LinkSubscription<AmqpSendLink> existing = openSendLinks.get(linkName);
if (existing != null) {
logger.atVerbose().log("Returning existing send link.");
return Mono.just(existing.getLink()); // No check if link is disposed/detached
}The cache key is the entity path (queue name), so only the affected queue's link is stale.
2. RetryUtil.java — no recovery between retries:
public static <T> Mono<T> withRetry(Mono<T> source, ...) {
return source.timeout(retryOptions.getTryTimeout())
.retryWhen(createRetry(retryOptions)); // Re-subscribes → gets same dead link
}Failure sequence:
1. External event detaches queue-a's sender link
2. openSendLinks cache still holds the dead link
3. sendMessage() → cache returns dead link → link.send() hangs → tryTimeout (60s)
4. retryWhen re-subscribes → same cache → same dead link → hangs again
5. After 4 attempts (245.6s total) → TimeoutException
6. Cache unchanged → next call repeats → permanent until JVM restart
Relationship to PR #48460
PR #48460 adds RecoveryKind classification, but its classify() method returns NONE for TimeoutException:
// PR #48460 — RecoveryKind.java
if (error instanceof TimeoutException) {
return NONE; // "Timeouts — retry on same link, the link may still be healthy"
}This assumption ("timeout = link is healthy") is exactly what breaks in this scenario. The link is not healthy — it's detached and will never respond. The timeout is a symptom of a dead link, not a transient server delay.
Suggested fix approaches (non-exhaustive):
- Cache-level: Add a liveness check in
ReactorSessionbefore returning cached links (e.g.,existing.getLink().isDisposed()) - Retry-level: Track consecutive timeouts on the same link; after N consecutive timeouts, escalate from
NONEtoLINKrecovery (close + recreate) - Both: Defense in depth
Setup:
- OS: Linux (AKS node)
- Library:
com.azure:azure-messaging-servicebus:7.15.1,com.azure:azure-core-amqp:2.9.1 - Java version: 17
- App Server/Environment: Spring Boot on Azure Kubernetes Service (AKS)
- Frameworks: Spring Boot
Additional context
- Related (all closed): Add tiered send recovery to match Go/.NET/Python/JS SDK parity — stale connection causes permanent sender stuck #48447, [BUG] Servicebus-Java ''Timeout on blocking read' when sending messages' #44688, [BUG] Message sending in ServiceBus queue occasionally fails with error "Cannot send a message when request response channel is disposed" or "Timeout on blocking read" #43877, ServiceBus Client is not surfacing connection errors #39154
- PR Add tiered send/receive recovery to azure-core-amqp and azure-messaging-servicebus #48460 (draft, stalled since 2026-08) attempts to add tiered recovery but does not cover this
TimeoutExceptionvariant - All other Azure SDK languages (Go, .NET, Python, JS) implement link-level recovery that would prevent this — see cross-SDK parity analysis in Add tiered send recovery to match Go/.NET/Python/JS SDK parity — stale connection causes permanent sender stuck #48447
Information Checklist
- Bug Description Added
- Repro Steps Added
- Setup information Added
Activity
github-actions commentedon Sep 17, 2026
Thank you for your feedback. Tagging and routing to the team member(s) best able to assist.
//cc: Eldert Grootenboer (@EldertGrootenboer) Srini Karri (@skarri-microsoft) Johnathan W (@j7nw4r)
github-actions commentedon Sep 17, 2026
🎯 Agentic Issue Triage
Summary: When a Service Bus AMQP sender link is silently detached (e.g., by infrastructure idle timeout on Kubernetes),
ServiceBusSenderClient.sendMessage()permanently hangs for the full retry budget (~245.6s) on every subsequent call for that entity, because the dead link is cached inReactorSession.openSendLinkswithout a liveness check and retries re-subscribe to the same dead link.📋 Issue Details
Package:
com.azure:azure-messaging-servicebus:7.15.1,com.azure:azure-core-amqp:2.9.1Affected API:
ServiceBusSenderClient.sendMessage(),ReactorSession.openSendLinks(cache),RetryUtil.withRetry()Scenarios:
Root ask: Detect a stale/detached sender link (proactively via liveness check, or reactively after repeated timeouts) and recreate it so the client recovers without requiring a process restart, matching behavior in Go/.NET/Python/JS SDKs.
🔎 Debugging / Reproduction Notes
Reporter provides a detailed root-cause analysis pointing to
ReactorSession.java(cache lookup with no liveness check) andRetryUtil.java(retry re-subscribes without recovery), plus references to draft PR #48460 which addsRecoveryKindclassification but currently returnsNONEforTimeoutException, which does not cover this scenario.Related issues referenced by the author (all closed): #48447, #44688, #43877, #39154. Of these, #48447 is a very similar previously-filed issue on the same theme (tiered send recovery / stale connection) that is still open and carries labels
Service Bus+needs-triage(missing a category label, so it was not usable as a quality reference pair, but it is a strong topical match).Suggested investigation steps:
ReactorSession.openSendLinkscache population/eviction logic and whether aisDisposed()/liveness check can be added before returning a cached link.RetryUtil.withRetry()and theRecoveryKindclassification added in draft PR Add tiered send/receive recovery to azure-core-amqp and azure-messaging-servicebus #48460 to determine whetherTimeoutExceptionshould escalate toLINKrecovery after N consecutive timeouts on the same link.🏷️ Label Confidence
Client— The issue is entirely about SDK-internal caching/retry behavior inazure-messaging-servicebus/azure-core-amqp, not a REST API or service-side behavior issue.Service Bus— The issue explicitly namesServiceBusSenderClient,com.azure:azure-messaging-servicebus, and is under the/sdk/servicebus/area.👥 Owner Routing
# ServiceLabel: %Service Bus(line 455) — matches on the single "Service Bus" service label; scan started from end of file upward and this was the first fully-matching# ServiceLabel:entry for the predicted labels.@EldertGrootenboer@skarri-microsoft@j7nw4r# ServiceLabel: %Service Bus %Track 1entry (line 459, lists an AzureSdkOwners set) requires both "Service Bus" and "Track 1" labels — since "Track 1" was not predicted, it did not match and was skipped. No other later entries in the file matched "Service Bus" alone.Note: The Maven deprecated-package lookup against the Azure SDK release-metadata CSV could not be completed in this run due to network restrictions on
web-fetch/curlfor the raw GitHub content URL.azure-messaging-servicebusis an actively maintained, non-deprecated core SDK package, so this is not expected to change the outcome.sunghyun1999 commentedon Sep 17, 2026
Submitted a fix in #50505 — adds an
isDisposed()liveness check toReactorSession's cached link lookup, so disposed (detached) links are evicted from the cache and recreated instead of being returned stale.The fix is minimal (single check at cache boundary) and orthogonal to the broader tiered recovery work in #48460.