Repository navigation
修复 PLUGIN_TIMEOUT 超时后仍等待慢任务的问题 - #153
Closed
henrycjchen wants to merge 1 commit into
Closed
henrycjchen wants to merge 1 commit into
henrycjchen wants to merge 1 commit into
Conversation
ExecuteBatchWithTimeout 超时后 GetResults 会按时返回,但 defer pool.Close() 中的 wg.Wait() 会阻塞到所有仍在执行的任务结束,导致整批耗时仍等于最慢的 插件/频道,超时只丢结果不提速。 - 超时时在后台关闭工作池,调用方按超时时间拿到已完成的结果 - worker 发送结果时同时监听 ctx,超时后不再阻塞在 results 通道上 Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Author
|
上游已在 d84c20e 中以更完整的方式修复(Shutdown(wait=false) + Task 接收 ctx),关闭此 PR。 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
PLUGIN_TIMEOUT设了之后只丢结果,不缩短耗时。pool.ExecuteBatchWithTimeout(TG 频道和插件搜索共用)到超时后,GetResults会按时返回,但defer pool.Close()里的p.wg.Wait()会一直阻塞,直到所有还在跑的任务结束。task()本身不能被中断,所以整批耗时还是等于最慢的那个插件或频道。复现:某个插件要 17s 左右(例如 hdmoli,它内部自带 30s 超时加重试),设
PLUGIN_TIMEOUT=5,src=plugin仍然要 17s,而且超时后完成的那部分结果被丢掉了。修改
ExecuteBatchWithTimeout:收集结果后,如果没收齐(超时),就在后台go pool.Close(),调用方按超时时间拿到已完成的结果。正常全部完成的情况还是同步关闭,行为不变。ctx.Done()。超时后没人再读results,这样可以避免后台 worker 阻塞在通道上泄漏,也保证后台Close()能结束。util/pool/worker_pool_test.go,覆盖超时和全部完成两种情况。验证
go test -race -count=3 ./util/pool/通过(修复前超时用例耗时 2s,失败)。PLUGIN_TIMEOUT=5、CACHE_ENABLED=false,/api/search?src=plugin&refresh=true:🤖 Generated with Claude Code