Skip to content

Prevent resource adapter delivery stalls during session handoff and WorkManager rejection - #2938

Closed
cshannon wants to merge 2 commits into
apache:mainfrom
cshannon:fix/2645-2647-ra-session-recovery
Closed

cshannon wants to merge 2 commits into
apache:mainfrom
cshannon:fix/2645-2647-ra-session-recovery

Conversation

@cshannon

@cshannon cshannon commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

Fixes two independent causes of stalled message delivery in activemq-ra, in separate commits:

  • ServerSessionPoolImpl duplicates active/idle session entries #2645 — Session handoff: Coordinate the queue-empty check, idle return, and session start under the pool lock so dispatch cannot strand a message. Preserve the public returnToPool() method without allowing duplicate returns or returning a session that still has a worker.
  • ServerSessionImpl gets stuck if the WorkManager encounteres a RejectedExecutionException #2647 — WorkManager rejection: Retry rejected delivery and reconnect work with capped backoff, including rejection after acceptance. Handle a callback and a thrown exception for the same submission only once. Prefer the container timer and fall back to a daemon timer if needed. Where the container permits adapter-owned threads, run potentially blocking submissions off the timer so one retry does not delay another. Cancel pending retries on shutdown and prevent a retry already in flight from delivering on a stopped session. The WorkManager still executes delivery and connection work. Reconnect submissions do not hold endpoint locks, so a blocked WorkManager call cannot delay shutdown. Work accepted after shutdown cannot reconnect a stopped or restarted endpoint. Known nonretryable failures use the existing failure path; sustained retryable rejection logs at WARN once backoff reaches its cap.

Verification: All 20 focused Maven tests passed (WorkRejectionRecoveryTest, ServerSessionHandoffTest, and the delivery, parallel delivery, and async stop cases in MDBTest). Coverage includes stopping during a blocked reconnect submission, ignoring stale work after restart, surfacing nonretryable rejection, and warning on sustained rejection while retaining recovery.

Fixes #2645
Fixes #2647

Note: This stuff is very difficult to get right so I obviously worked with an LLM to generate the fixes here and went back and forth a few times.

@cshannon cshannon self-assigned this Dec 3, 2026
@cshannon
cshannon requested review from jeanouii and mattrpav December 3, 2026 23:22
Coordinate the pending-message check and idle return with session start.
A dispatch holding a session that just went idle moves it back to active
before submitting work.

Fixes apache#2645
@cshannon
cshannon force-pushed the fix/2645-2647-ra-session-recovery branch from 1e7ae70 to 0e671fb Compare December 3, 2026 23:30
@cshannon cshannon changed the title Fix resource adapter session handoff and recover from WorkManager rejection Prevent resource adapter delivery stalls during session handoff and WorkManager rejection Dec 3, 2026
Retry checked and unchecked WorkManager rejections with capped backoff,
including rejection after acceptance. Handle each submission rejection
once even when the WorkManager reports it by callback and by throwing.

Retry delivery without disconnecting a healthy broker connection and
retry rejected endpoint connection work separately. Prefer a container
timer and fall back to a daemon timer that only resubmits work. Cancel
retries when the endpoint stops.

Submit connection work outside endpoint locks and ignore stale submissions
after a stop or restart. Surface known nonretryable failures immediately
and log sustained retryable rejection at WARN.

Fixes apache#2647
@cshannon
cshannon force-pushed the fix/2645-2647-ra-session-recovery branch from 0e671fb to 07e44bf Compare December 3, 2026 23:39
@cshannon
cshannon marked this pull request as draft December 3, 2026 23:43
@cshannon

cshannon commented Dec 3, 2026

Copy link
Copy Markdown
Contributor Author

I ran some further testing on this and I think there's some regressions, I'm going to close it for now and keep working on it before submitting again so I stop force pushing.

@cshannon cshannon closed this Dec 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ServerSessionImpl gets stuck if the WorkManager encounteres a RejectedExecutionException ServerSessionPoolImpl duplicates active/idle session entries

1 participant