Skip to content

[Bug]: MORPC FIN can deadlock with session close while its ACK is pending #29560

Closed

Description

@XuPeng-SH

Description

On the current main, a server-side MORPC stream FIN can deadlock with client-session shutdown if the FIN ACK has been queued but the writer exits before completing it. This was observed during cleanup after the five SQL subtests of TestJoinCoordinatorStage had passed; the test cluster then failed to shut down. This is a transport lifecycle bug, not a SQL/query failure.

Root cause

clientSession.FinishStream held streamStateMu while waiting for the FIN send Future to complete. If the server writer exits, its deferred session close needs the same mutex before it can drain and fail queued sends. The two paths then wait on each other:

  1. FIN waits for the queued ACK Future while holding streamStateMu.
  2. Session close waits for streamStateMu before draining/failing that Future.
  3. Server shutdown waits for the writer/session cleanup to finish.

Reproduction evidence

  • Baseline: main at 113d374b2e5167238d8411c117dfe879aef8bad6.
  • A deterministic white-box probe registers a stream request, queues its FIN ACK without a live writer, then concurrently calls FinishStream and session Close. On baseline, both calls remain blocked until the probe manually drains the pending Future.
  • CI observation: PR #29549 UT job completed all five TestJoinCoordinatorStage SQL subtests, then timed out during cluster cleanup.

Expected behavior

Session shutdown must be able to drain/fail a pending FIN ACK and let both FIN completion and server shutdown terminate, without holding the stream-state lock across a potentially blocking send completion wait.

Regression coverage

The regression is exercised by the MORPC lifecycle tests added in PR #29559, including queued FIN with no writer, writer exit/Stopper completion, duplicate FIN/later-request exclusion, and exact message/Future release accounting.

Related

This is a concrete MORPC FIN/session-close lock cycle in the broader pipeline termination/lifecycle area tracked by #24971; it is not the already-fixed client-side full receive-channel deadlock in #25943.

Activity

  1. added
    kind/bug
    on Oct 1, 2026
  2. self-assigned this
    on Oct 1, 2026
  3. added a commit that references this issue on Oct 1, 2026
    32f5498
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions