You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: morpc Stream.Close(false) deadlocks behind a full receive channel #25943
morpc.stream.done holds s.mu.RLock() while sending a response to the bounded receive channel. When that channel is full and the response context has no deadline, the send blocks indefinitely while retaining the read lock.
At the same time, Stream.Close(false) needs s.mu.Lock() before it can drain the channel and mark the stream closed. It therefore cannot make progress, producing a lock/channel deadlock:
The receive channel is full.
Another response enters stream.done, obtains RLock, and blocks on s.c <- response.
The caller invokes Close(false).
Close(false) waits for the write lock, but only Close can drain the channel and unblock done.
Close(true) can avoid this in some cases by stopping the backend first, but the normal Close(false) API has no cancellation path for the blocked delivery.
Impact
A caller that stops consuming a stream and closes it while responses are still arriving can hang permanently. This can leak the stream, block cleanup, and leave callers waiting forever during cancellation or shutdown.
Reproduction
A white-box test with a receive channel of capacity one:
Deliver sequence 1 to fill the channel.
Deliver sequence 2 with context.Background() in another goroutine; it blocks while holding RLock.
Call Close(false) and wait for it to return.
The audit was run three times. All 3/3 runs showed Close(false) still blocked after 200 ms; it returned only after the test manually drained the first response.
go test ./pkg/common/morpc \
-run '^TestAuditStreamCloseDoesNotBlockBehindFullReceiveChannel$' \
-count=3 -v
Expected behavior
Stream.Close(false) must promptly cancel or otherwise unblock pending response delivery, even when the receive channel is full and unread.
GitHub main was checked again before filing and still holds RLock across the blocking channel send.
Suggested direction
Do not hold the stream read lock across a potentially blocking channel send. Introduce a stream-local cancellation signal that both done and Close select on, or otherwise arrange for close to unblock pending delivery before acquiring the exclusive lock.
检查 Close 是否可以主动解除等待并及时返回,同时检查关闭后的 stream/channel 不会被错误复用。
执行命令:
go test ./pkg/common/morpc \
-run '^(TestCloseStreamUnblocksFullReceiveChannel|TestClosedStreamHandleAndChannelAreNotReused)$' \
-count=10
go test -race ./pkg/common/morpc \
-run '^TestCloseStreamUnblocksFullReceiveChannel$' \
-count=1
Activity
fix(morpc): terminate pending work during backend and stream close (#…
Ariznawlll commentedon Jul 22, 2026
已在最新
main上完成验证,结论:该问题已修复。测试版本
main50319026a69e45c3c190cb7a09e9c5fbdb7f6857e917fbfc5测试步骤
Stream.Close(false)。执行命令:
测试结果
-race模式通过,未发现数据竞争。Close(false)仍能及时返回。因此,原 issue 中“
Stream.Close(false)被满接收通道永久阻塞”的死锁在当前 main 上未再复现。该问题必须构造 morpc 内部通道和锁状态,属于稳定的白盒并发测试,不适合加入 motr SQL 黑盒回归。
fix(morpc): terminate pending work during backend and stream close (m…
fix(morpc): terminate pending work during backend and stream close (m…
fix(morpc): terminate pending work during backend and stream close (m…