Skip to content

[Bug]: closing a morpc backend leaves response-waiting Futures blocked #25945

Closed

Description

@Ariznawlll

Bug description

Closing a morpc.remoteBackend does not complete futures whose requests were already written and are waiting for responses.

When the backend context is canceled, readLoop can exit through the ctx.Done() branch:

case <-ctx.Done():
    normalExit = true
    rb.clean()
    return

rb.clean() only deletes entries from rb.mu.futures; it does not call Future.error. A Future that has already received its write completion therefore remains blocked in Get() until its caller-owned request context expires, even though the backend is definitively closed.

Impact

  • In-flight RPC calls do not fail promptly when a client/backend is closed.
  • Shutdown and cancellation can remain blocked until long business deadlines expire.
  • The backend loses the future from its tracking map without delivering a terminal result.

Reproduction

Using a real local morpc connection:

  1. Let the server accept a request without replying.
  2. Wait until the Future reports that the request was successfully written.
  3. Call remoteBackend.Close().
  4. Call Future.Get() with a 30-second request context.

The audit ran this sequence three times. In all 3/3 runs, Get() was still blocked after the backend and both read/write loops had stopped; it returned only after the test explicitly canceled the request context.

go test ./pkg/common/morpc \
  -run '^TestAuditCloseBackendCompletesFutureAlreadyWaitingForResponse$' \
  -count=3 -v

Expected behavior

Backend.Close() must complete every tracked Future with a closed/canceled backend error, including requests already written and waiting for a response.

Tested version

  • Audit baseline: main@7f9ef5de9bb9337d8db0a9b15c44cba3b2838aa2
  • GitHub main was checked before filing and still uses rb.clean() without notifying waiting futures.

Suggested direction

Before removing tracked futures during backend shutdown, notify them with a terminal backend-closed error. Keep future-map cleanup and notification ordering safe with respect to Future.Close and pool reuse.

Activity

  1. added this to the MO-202607 milestone on Jul 21, 2026
  2. added
    kind/bug
    on Jul 21, 2026
  3. added theissue type on Jul 21, 2026
  4. added a commit that references this issue on Jul 22, 2026
    e917fbf
  5. assigned and unassigned on Jul 22, 2026
  6. Ariznawlll commented on Jul 22, 2026

    @Ariznawlll
    CollaboratorAuthor

    已在最新 main 上完成验证,结论:该问题已修复。

    测试版本

    • MatrixOne 分支:main
    • MatrixOne commit:50319026a69e45c3c190cb7a09e9c5fbdb7f6857
    • 对应修复:PR #26004,commit e917fbfc5

    测试步骤

    1. 启动真实本地 morpc server/client 连接。
    2. server 接收请求但暂不返回 response,使 Future 进入“请求已经写出、正在等待响应”的状态。
    3. 调用 remoteBackend.Close(),模拟 backend 关闭。
    4. 检查正在等待响应的 Future 是否立即收到终止错误,而不是一直阻塞到业务 context 超时。
    5. 同时覆盖关闭后的 stream、handle、channel 不被错误复用,以及移除 active stream 时不长期持有 backend mutex 的路径。

    执行命令:

    go test ./pkg/common/morpc \
      -run '^(TestCloseBackendNotifiesWaitingFuture|TestClosedStreamHandleAndChannelAreNotReused|TestRemoveActiveStreamDoesNotHoldBackendMutexWhileUnlocking)$' \
      -count=10
    
    go test -race ./pkg/common/morpc \
      -run '^TestCloseBackendNotifiesWaitingFuture$' \
      -count=1
    

    测试结果

    • 普通模式连续 10 轮通过。
    • -race 模式通过,未发现数据竞争。
    • backend 关闭后,已经写出且正在等待 response 的 Future 会立即结束并返回关闭错误。
    • Future 不再依赖调用方的长超时 context 才能退出。
    • 清理过程没有残留阻塞 goroutine。

    因此,issue 描述的“关闭 backend 后等待响应的 Future 仍长期阻塞”在当前 main 上未再复现。

    该场景依赖 morpc 内部 Future/stream/backend 生命周期,属于白盒并发测试,不适合转换为 motr SQL 黑盒用例;回归由 MatrixOne morpc UT 和 race 测试覆盖。

  7. added 3 commits that reference this issue on Sep 17, 2026
    e01ce65
    ea615fe
    51f05e9
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

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions