🟡 [M6] 后台线程在有界通道上阻塞 send #16

Closed
opened 2026-06-03 13:53:56 +08:00 by dailz · 1 comment
Owner

文件: core/io/progressive_reader.rs:302,328
分类: 并发 / 通道

问题: 后台 worker 线程使用阻塞 send 在有界通道(容量 10)上。如果消费者暂停,线程无限挂起,持有资源且无法到达完成/取消检查。

建议修复: 进度消息使用 try_send,始终优先发送最终状态,或使用 select! 加取消。

**文件**: `core/io/progressive_reader.rs:302,328` **分类**: 并发 / 通道 **问题**: 后台 worker 线程使用阻塞 `send` 在有界通道(容量 10)上。如果消费者暂停,线程无限挂起,持有资源且无法到达完成/取消检查。 **建议修复**: 进度消息使用 `try_send`,始终优先发送最终状态,或使用 `select!` 加取消。
dailz added the area/concurrencyseverity/mediumbug labels 2026-06-03 13:53:56 +08:00
dailz closed this issue 2026-06-09 15:14:47 +08:00
Author
Owner

已修复,提交 0d88e93。

根因: spawn_indexer 和 spawn_visual_height_rebuild 的后台线程使用阻塞 tx.send() 在有界通道上,consumer 停止 drain 时线程永久挂起,取消检查不可达。

修复方案:

  • Progress 消息: tx.try_send() — 通道满时丢弃,扫描循环永不阻塞
  • Complete/Error 消息: send_cancelable() — 基于 crossbeam select! 的泛型辅助函数,发送成功或收到取消信号时返回,线程零 CPU 开销睡眠等待
  • Drop 中取消信号: tx.try_send() — Drop 永不阻塞
  • spawn_visual_height_rebuild 的 bounded(1) 通道同样修复

测试: 5 个新增测试覆盖满通道+取消场景,全量 379 测试通过。

已修复,提交 0d88e93。 **根因**: spawn_indexer 和 spawn_visual_height_rebuild 的后台线程使用阻塞 tx.send() 在有界通道上,consumer 停止 drain 时线程永久挂起,取消检查不可达。 **修复方案**: - Progress 消息: tx.try_send() — 通道满时丢弃,扫描循环永不阻塞 - Complete/Error 消息: send_cancelable<T>() — 基于 crossbeam select! 的泛型辅助函数,发送成功或收到取消信号时返回,线程零 CPU 开销睡眠等待 - Drop 中取消信号: tx.try_send() — Drop 永不阻塞 - spawn_visual_height_rebuild 的 bounded(1) 通道同样修复 **测试**: 5 个新增测试覆盖满通道+取消场景,全量 379 测试通过。
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: dailz/logViewer#16