goroutineresourceleak: checkChannelLeak misses usage via function-call indirection (channel_usage_indirection_blind)
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
阅读 pkg/linters/goroutineresourceleak/goroutineresourceleak.go,重点关注 checkChannelLeak 和 markChannelUsage,然后查看 testdata/src/a/a.go 中第 259-318 行附近的 SAFE PATTERNS。添加所述的辅助函数调用测试用例,并扩展使用情况扫描,使传递给辅助函数的 channel 不会被报告为泄漏。新用例通过且列出的现有正例和反例保持原有行为时,即完成。
由索引模型根据 Issue 内容生成。
描述
Problem
pkg/linters/goroutineresourceleak/goroutineresourceleak.go checkChannelLeak (lines 149-171), backed by createdChannels and markChannelUsage (lines 173-236), only recognizes a channel as used inside a spawned goroutine via three direct AST shapes within the goroutine body itself: a SendStmt (ch <- v), a literal close(ch) call, or a unary receive (<-ch). There is no handling for a channel being passed as an argument to another function call, stored into a struct field or closure, or returned -- all common decomposition patterns where the real send/receive/close happens inside the callee rather than inline in the goroutine body.
This causes a false-positive channel leak report on perfectly safe code: a goroutine that creates a channel and immediately hands it off to a well-behaved helper function (for example go func() { ch := make(chan int); process(ch) }(), where process does the actual send/receive/close) has zero recognized usage events under the current scan, so it falls through every safe-pattern check in checkChannelLeak and gets flagged as a leak.
Evidence
- goroutineresourceleak.go:159-160 -- channels := createdChannels(pass, body); markChannelUsage(pass, body, channels), both walk only the goroutine's own body via ast.Inspect (excluding FuncLit boundaries)
- goroutineresourceleak.go:208-233 -- markChannelUsage checks only *ast.SendStmt, a close(...) CallExpr, and a token.ARROW UnaryExpr; no case handles a channel identifier appearing as a plain CallExpr argument, a composite literal field, or a return value
- testdata/src/a/a.go:259-318 (SAFE PATTERNS section) has zero coverage for a channel passed to a helper function -- every existing safe case either uses one of the three recognized syntactic forms directly inline, or is a named-function goroutine (go doSomeWork()), which is explicitly out of scope for the whole check per the namedFunctionGoroutine comment
- This is distinct from the already-filed paren_unwrap_gap (#68591) and adjacent_defer_assumption (#68945) issues on this same linter, which affect checkCancelLeak/checkMutexLeak rather than checkChannelLeak
Recommendation
Extend markChannelUsage to also treat a channel identifier appearing as a CallExpr argument (or in a composite literal / return statement) as a usage event, at least conservatively marking it as both sent-and-received to suppress the diagnostic -- a full call-graph analysis is out of scope for an AST-heuristic linter, but a channel handed to any opaque call should not be treated as provably unused.
Validation checklist
- Add a testdata case: ch := make(chan int); process(ch) where process is an external/unanalyzed function -- should NOT be flagged
- Confirm existing positive cases (channelWithoutUse, channelWithSend, channelWithReceive, channelWithUnbufferedSequentialSendAndReceive) still correctly flag
- Confirm existing negative cases (channelWithClose, channelWithBufferedSendAndReceive) still correctly pass
Effort
Small -- one function (markChannelUsage) plus one new testdata fixture.
Pattern class: channel_usage_indirection_blind (new -- a resource-usage scan recognizing only a closed set of direct syntactic forms, with no awareness of usage via a function-call indirection).
Generated by 🤖 Sergo - Serena Go Expert · claude · agent · 211.8 AIC · ⌖ 0.49 AIC · ⊞ 5.3K · ◷
- expires on Oct 23, 2026, 7:59 PM UTC-08:00
- 主要语言
- Go
- 星标
- 5.4k
- 派生
- 584
- 平均合并
- 3 小时 16 分钟
- 30 天内合并 PR
- 829
环境准备
在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。
- 提供 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
github/gh-aw 的其他 Issue
-
automation models
难度 2/5 1-3 小时 新手友好度 70/100
维护者通常 1 天内回复
-
agentic-workflows
难度 2/5 1-3 小时 新手友好度 66/100
维护者通常 1 天内回复
-
cookie delight
难度 1/5 1-3 小时 新手友好度 88/100
维护者通常 1 天内回复
-
automation cookie dependencies go-fan
难度 2/5 1-3 小时 新手友好度 74/100
维护者通常 1 天内回复
-
agentic-workflows automation aw-essential cookie
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 72/100
apache/rocketmq-dashboard#7243 ·
维护者通常 3 天内回复
-
Missing example coverage: getClock可能已有人在做 @camunda-sdk-automation 今天认领。 未关闭new-operations
难度 2/5 1-3 小时 新手友好度 62/100
camunda/orchestration-cluster-api-go#75 · 2 条评论 ·
维护者通常 1 天内回复
-
[schema-coverage] elasticstack_kibana_security_entity_store_status可能已有人在做 @github-actions 今天认领。 未关闭acceptance-tests phase-coding schema-coverage testing triaged
难度 2/5 1-3 小时 新手友好度 68/100
elastic/terraform-provider-elasticstack#5396 ·
维护者通常 1 天内回复
-
Go device SDK: Whisper transcriber keeps buffering and transcribing audio appended after Stop()可能已有人在做 @apoorvdarshan 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 84/100
BasedHardware/omi#22770 ·
维护者通常 1 天内回复
-
Bug v3
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复