Skip to content

[Bug]: ISCP index consumer deadlocks after downstream SQL execution fails #25632

Closed

Description

@Ariznawlll

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 nil

Any 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:

  1. The producer sends row 1.
  2. runIndex receives it, the executor returns the injected error, runIndex writes errch and exits.
  3. The producer processes row 2 and blocks sending to sqlBufSendCh because 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 Consume promptly.
  • Channel sends must select on context cancellation and consumer failure.
  • sinkTail must return flushCdc() 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

  1. added this to the MO-202607 milestone on Jul 11, 2026
  2. added theissue type on Jul 11, 2026
  3. added
    severity/s0
    kind/bug
    and removed on Jul 12, 2026
  4. added a commit that references this issue on Jul 14, 2026
  5. jiangxinmeng1 commented on Jul 14, 2026

    @jiangxinmeng1
    Contributor

    fixed by #25666

  6. Ariznawlll commented on Jul 14, 2026

    @Ariznawlll
    CollaboratorAuthor

    已在最新 main 上验证 ISCP index consumer 的错误传播与退出路径。

    验证版本

    • Commit:0977fc07c51067ce76b769c7853d7374cb2fccec
    • 验证时间:2026-07-14

    验证方法

    go test ./pkg/iscp -run 'TestIndexConsumer|TestDataRetriever' -count=1 -v

    覆盖首批 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 上均未再出现。

    #25632 verification

  7. added
    ai-easy
    on Jul 15, 2026
  8. 2 remaining items

  9. added this to the MO-202609 milestone on Sep 2, 2026
  10. Ariznawlll commented on Sep 2, 2026

    @Ariznawlll
    CollaboratorAuthor

    发现 #25632 的修复遗漏了 Fulltext2 ISCP consumer 的取消路径,现重新打开该 issue 跟踪。

    复现版本

    • 分支:main
    • commit:edd17ecc02a2eb1ca1e5800858237c0410ca313c
    • 环境:macOS 本地源码白盒验证;使用真实 IndexConsumer.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 得到相同结果:

    --- FAIL: TestFulltext2ConsumerContextCancelUnblocksRetrieverNext (2.00s)
    fulltext2 consumer stayed blocked in DataRetriever.Next after context cancellation
    

    同一 main 上的普通索引对照 TestIndexConsumerContextCancelUnblocksRetrieverNext 连续 3 次均在取消后返回 context.Canceled。同一 Fulltext2 最小复现以 -race 执行,仍稳定暴露阻塞,未报告数据竞争。

    代码位置

    pkg/iscp/fulltext2_consumer.go:79-80:

    case <-ctx.Done():
        return

    这里需要遵循 runIndex / runHnsw 的错误传播契约,让 IndexConsumer.Consume 能解除正在等待下一批数据的生产端。

    回归覆盖

    建议在 pkg/iscp 增加 Fulltext2 版本的 ContextCancelUnblocksRetrieverNext 回归:固定 consumer 已进入循环、生产端已阻塞后再取消,并断言 Consume 有界返回 context.Canceled。

  11. Ariznawlll commented on Sep 5, 2026

    @Ariznawlll
    CollaboratorAuthor

    最新 main 验证结论

    • MatrixOne:最新 main
    • Commit:845fff8e9cac962c5002a1007e0b0180efd591b

    已通过的回归路径

    普通 IndexConsumer 的以下路径均已验证通过:

    • Snapshot 首批执行失败
    • Snapshot 中间批执行失败
    • Tail 首批执行失败
    • Tail 中间批执行失败
    • Final flush 错误传播
    • blocked send 期间 context cancellation
    • HNSW consumer 执行失败
    • 真实 2-CN FULLTEXT/HNSW failpoint 黑盒

    这些路径未再观察到原始 producer 永久阻塞或错误丢失。

    仍未修复的问题:Fulltext2 consumer 取消路径

    复现步骤:

    1. 使用真实 Fulltext2 consumer 和 IndexConsumer.Consume。
    2. 等待 Fulltext2 consumer 进入运行循环。
    3. 让 producer 阻塞在 DataRetriever.Next()。
    4. 取消同一个 context。
    5. 等待 Consume 返回。

    预期结果:Consume 在有界时间内返回 context.Canceled,并解除 producer 在 DataRetriever.Next() 上的阻塞。

    实际结果:

    • pkg/iscp/fulltext2_consumer.go 的 ctx.Done() 分支直接返回;
    • 没有通过 errch 向 IndexConsumer.Consume 传播取消错误;
    • Consume 无法调用 DataRetriever.SetError;
    • producer 继续阻塞在 DataRetriever.Next();
    • 2 秒内未返回。

    该最小复现连续 3/3 失败,使用 -race 仍稳定复现,未发现数据竞争。

    结论

    普通 IndexConsumer 的原始死锁路径已修复,但 Fulltext2 consumer 的 context cancellation 路径仍存在同类阻塞问题。请 @jiangxinmeng1 继续修复该路径;修复完成后再补充回归验证。Issue 暂不关闭。

  12. added a commit that references this issue on Oct 30, 2026
    b33a732
  13. MatrixAdventurer commented on Nov 1, 2026

    @MatrixAdventurer
    Contributor

    结论:已修复可关闭,@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智能体提交

  14. Ariznawlll commented on Nov 3, 2026

    @Ariznawlll
    CollaboratorAuthor

    结论

    测试通过。原索引 consumer 的执行失败和取消可以传回生产端;重新打开本 Issue 时发现的 Fulltext2 取消阻塞路径也已复验通过。

    关键证据

    • 2026-11-03 基于官方 main@d61a7206c16b30baa4efc525eb6067c4364035aa,本地源码白盒和独立 LOG/TN、双 CN SQL 实例验证。
    • Unhappy case:真实 Fulltext2 consumer 的生产端进入 DataRetriever.Next() 后取消 consumer context,断言 Consume 有界返回 context.Canceled;等待输入时取消也断言错误传播和 worker 退出。普通索引下游执行失败、final flush 失败、blocked send 取消、worker 失败及 retriever 取消传播定向测试使用 -race -count=10 均通过。
    • Happy case:Fulltext2 索引建好后经 ISCP 同步 INSERT、UPDATE、DELETE;重复主键写入被拒后,后续合法写入仍能同步并被检索。新 MOTR 公开 SQL 控制连续 3 轮通过;Fulltext2 现有 CDC/rebuild BVT 59/59 通过,BVT 使用 -n 未比较结果集元数据。
    • MOTR PR #305 提交 ce3bc1d2(4 项离线 CI 通过) 增加公开 CDC 控制;阻塞 retriever 和取消传播属于内部注入路径,回归保留在主库 pkg/iscp/fulltext2_consumer_cancel_test.go,不将 SQL 控制称为对该内部故障的复现。本轮未重新执行历史双 CN FULLTEXT/HNSW 故障注入;上述双 CN SQL BVT 不等同于该注入。

    待解决点

    无。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

ai-easykind/bugseverity/s0

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions