Repository navigation
Description
Summary
IndexConsumer.Consume can deadlock permanently after the downstream index SQL executor returns an error. The execution goroutine reports the error and exits, but the producer continues flushing to an unbuffered sqlBufSendCh with no remaining receiver.
This affects asynchronous index maintenance, including FULLTEXT and IVF_FLAT; HNSW uses the same producer/channel pattern with a different consumer loop.
Version
Commit: 7f7de555c
Code path
pkg/iscp/index_consumer.go:
func (c *IndexConsumer) sendSql(writer IndexSqlWriter) error {
// ...
c.sqlBufSendCh <- sql
writer.Reset()
return nil
}The send does not select on ctx.Done() or the error channel. In runIndex, an ExecWithResult error is sent to errch and the goroutine returns. The producer does not read errch while generating data, so its next sendSql blocks forever.
There is a second error-propagation bug at the end of sinkTail:
c.flushCdc()
return nilAny final flush error is discarded.
White-box reproduction
A focused test used a writer that flushes after every row and an ExecWithResult stub that fails the first SQL with injected index SQL failure:
- The producer sends row 1.
runIndexreceives it, the executor returns the injected error,runIndexwriteserrchand exits.- The producer processes row 2 and blocks sending to
sqlBufSendChbecause no receiver exists.
The test runs Consume in a goroutine and requires the injected error within two seconds.
Actual result
Consume deadlocked after the SQL executor returned an error
The original executor error is never returned to the caller.
Expected result
- A downstream execution error must cancel/stop the producer and be returned by
Consumepromptly. - Channel sends must select on context cancellation and consumer failure.
sinkTailmust returnflushCdc()errors.- Closing or abandoning the channel must not leave either goroutine blocked.
Suggested verification
Cover execution failure on the first and middle batch for snapshot and tail consumers, final-flush failure, context cancellation during a blocked send, and the HNSW consumer variant.
Activity
Fix index consumer deadlock (#25666)
jiangxinmeng1 commentedon Jul 14, 2026
fixed by #25666
Ariznawlll commentedon Jul 14, 2026
已在最新
main上验证 ISCP index consumer 的错误传播与退出路径。验证版本
0977fc07c51067ce76b769c7853d7374cb2fccec验证方法
覆盖首批 SQL 执行失败、consumer 已退出后继续生产、unbuffered channel blocked send、context cancellation、tail final flush error 以及被拒 batch 的资源释放。
实际结果
执行器注入错误能够立即返回给
Consume;生产者不会继续永久阻塞在sqlBufSendCh;最终flushCdc()错误也能返回;取消 retriever/blocked send 均能正常退出。相关回归全部 PASS。结论
原 issue 中“下游 SQL executor 退出后 producer 永久死锁”和“尾部 flush 错误被吞掉”两条路径在当前 main 上均未再出现。
2 remaining items
Ariznawlll commentedon Sep 2, 2026
发现 #25632 的修复遗漏了 Fulltext2 ISCP consumer 的取消路径,现重新打开该 issue 跟踪。
复现版本
mainedd17ecc02a2eb1ca1e5800858237c0410ca313cIndexConsumer.Consume、DataRetriever与 Fulltext2 consumer 循环。复现步骤与结果
最小场景先等待 Fulltext2 consumer 进入运行循环,再让生产端阻塞在
DataRetriever.Next(),随后取消同一个 context。预期:取消应经 consumer 回传到 retriever,使
Consume在 2 秒内返回context.Canceled。实际:
pkg/iscp/fulltext2_consumer.go在ctx.Done()分支直接返回,未向errch写入取消错误。IndexConsumer.Consume因而无法调用DataRetriever.SetError;生产端持续阻塞在DataRetriever.Next(),2 秒内不返回。最小复现连续 3/3 得到相同结果:
同一 main 上的普通索引对照
TestIndexConsumerContextCancelUnblocksRetrieverNext连续 3 次均在取消后返回context.Canceled。同一 Fulltext2 最小复现以-race执行,仍稳定暴露阻塞,未报告数据竞争。代码位置
pkg/iscp/fulltext2_consumer.go:79-80:这里需要遵循
runIndex/runHnsw的错误传播契约,让IndexConsumer.Consume能解除正在等待下一批数据的生产端。回归覆盖
建议在
pkg/iscp增加 Fulltext2 版本的ContextCancelUnblocksRetrieverNext回归:固定 consumer 已进入循环、生产端已阻塞后再取消,并断言Consume有界返回context.Canceled。Ariznawlll commentedon Sep 5, 2026
最新 main 验证结论
main845fff8e9cac962c5002a1007e0b0180efd591b已通过的回归路径
普通 IndexConsumer 的以下路径均已验证通过:
这些路径未再观察到原始 producer 永久阻塞或错误丢失。
仍未修复的问题:Fulltext2 consumer 取消路径
复现步骤:
Fulltext2 consumer和IndexConsumer.Consume。DataRetriever.Next()。Consume返回。预期结果:
Consume在有界时间内返回context.Canceled,并解除 producer 在DataRetriever.Next()上的阻塞。实际结果:
pkg/iscp/fulltext2_consumer.go的ctx.Done()分支直接返回;errch向IndexConsumer.Consume传播取消错误;Consume无法调用DataRetriever.SetError;DataRetriever.Next();该最小复现连续 3/3 失败,使用
-race仍稳定复现,未发现数据竞争。结论
普通 IndexConsumer 的原始死锁路径已修复,但 Fulltext2 consumer 的 context cancellation 路径仍存在同类阻塞问题。请 @jiangxinmeng1 继续修复该路径;修复完成后再补充回归验证。Issue 暂不关闭。
Fix index consumer deadlock (matrixorigin#25666)
Fix index consumer deadlock (matrixorigin#25666)
Fix index consumer deadlock (matrixorigin#25666)
fix: unblock Fulltext2 ISCP retriever on cancellation (#31859)
MatrixAdventurer commentedon Nov 1, 2026
结论:已修复可关闭,@jiangxinmeng1 请复核确认关闭。证据:#31859 已合入 main(2026-10-30,+166/-0):pkg/iscp/fulltext2_consumer.go 在 RunFulltext2 主循环入口新增 ctx.Err() 预检,并在 case <-ctx.Done() 分支调用 reportIndexConsumerErr(errch, ctx.Err()),与普通索引路径一致,取消时可解除生产端 DataRetriever.Next() 阻塞;新增 pkg/iscp/fulltext2_consumer_cancel_test.go 回归:TestFulltext2ConsumerContextCancelUnblocksRetrieverNext(进入 Next() 后仅取消 consumer ctx,断言 Consume 有界返回 context.Canceled)、TestFulltext2ConsumerCancelWhileWaitingForInput(等待输入时取消,断言 errch 收到 context.Canceled 且 worker 退出)。issue 其余路径此前已在 main 验证通过;本 issue 范围仅 main,无缺口。
本操作由LW授权的MOI智能体提交
Ariznawlll commentedon Nov 3, 2026
结论
测试通过。原索引 consumer 的执行失败和取消可以传回生产端;重新打开本 Issue 时发现的 Fulltext2 取消阻塞路径也已复验通过。
关键证据
main@d61a7206c16b30baa4efc525eb6067c4364035aa,本地源码白盒和独立 LOG/TN、双 CN SQL 实例验证。Fulltext2consumer 的生产端进入DataRetriever.Next()后取消 consumer context,断言Consume有界返回context.Canceled;等待输入时取消也断言错误传播和 worker 退出。普通索引下游执行失败、final flush 失败、blocked send 取消、worker 失败及 retriever 取消传播定向测试使用-race -count=10均通过。-n未比较结果集元数据。ce3bc1d2(4 项离线 CI 通过) 增加公开 CDC 控制;阻塞 retriever 和取消传播属于内部注入路径,回归保留在主库pkg/iscp/fulltext2_consumer_cancel_test.go,不将 SQL 控制称为对该内部故障的复现。本轮未重新执行历史双 CN FULLTEXT/HNSW 故障注入;上述双 CN SQL BVT 不等同于该注入。待解决点
无。