pipedv1: stopSignal handler panics on closed channel upon concurrent or duplicate signal calls

未关闭 适合新手
#7,642 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@darshpatel1052 已经在做这个了。

开始于 2026年11月16日。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
72/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
go
领域
backend

调研方向

从 pkg/app/pipedv1/controller/stopsignal.go 第 70-91 行附近开始,其中 Cancel()、Timeout() 和 Terminate() 各自向 s.ch 发送,然后关闭它;阅读 NewStopSignal(),了解 channel 和 atomic.String 是如何设置的。用 sync.Once 保护发送路径(先设置 signal 并取消,然后恰好发送并关闭一次),并确认 pkg/app/pipedv1/controller/scheduler.go:370-395 中的消费者仍然收到一个值。将报告中的 TestStopSignal_Idempotency 用例添加到 controller 包的测试中,并运行 go test ./pkg/app/pipedv1/controller/...;完成意味着重复或并发调用不会 panic,并且 channel 只关闭一次。

由索引模型根据 Issue 内容生成。

描述

What happened:

In pkg/app/pipedv1/controller/stopsignal.go:70-91, Cancel(), Timeout(), and Terminate() directly send to s.ch and call close(s.ch):

func (s *stopSignal) Cancel() {
	s.signal.Store(string(StopSignalCancel))
	s.cancel()
	s.ch <- StopSignalCancel
	close(s.ch)
}

func (s *stopSignal) Timeout() {
	s.signal.Store(string(StopSignalTimeout))
	s.cancel()
	s.ch <- StopSignalTimeout
	close(s.ch)
}

func (s *stopSignal) Terminate() {
	s.signal.Store(string(StopSignalTerminate))
	s.cancel()
	s.ch <- StopSignalTerminate
	close(s.ch)
}

Although s.signal is an atomic.String, the channel operations (s.ch <- ... and close(s.ch)) are not guarded against multiple executions.

During stage execution (pkg/app/pipedv1/controller/scheduler.go:370-395), stage completion/cancellation is selected across multiple event sources: ctx.Done(), timer.C (deployment timeout), timeout (stage timeout), and s.cancelledCh (user cancellation):

select {
case <-ctx.Done():
	handler.Terminate()
	<-doneCh

case <-timer.C:
	handler.Timeout()
	<-doneCh

case cmd := <-s.cancelledCh:
...
	handler.Cancel()
	<-doneCh

case <-timeout:
	handler.Timeout()
	<-doneCh

case <-doneCh:
	break
}

If multiple signals arrive around the same time, or if Cancel/Timeout are called more than once:

  • Writing to s.ch after it was closed triggers panic: send on closed channel.
  • Calling close(s.ch) a second time triggers panic: close of closed channel.

Because this panic occurs inside the stage runner goroutine, it terminates the piped process.

What you expected to happen:

All signal emission methods (Cancel(), Timeout(), Terminate()) should be idempotent and thread-safe (e.g. using a sync.Once inside stopSignal). The first signal should register and close the channel, and subsequent invocations should safely return without panicking.

How to reproduce it:

The panic can be triggered with a two-line test:

func TestStopSignal_Idempotency(t *testing.T) {
	_, handler := NewStopSignal()
	handler.Timeout()
	handler.Cancel() // Panics immediately with: panic: send on closed channel
}

Environment:

  • piped version: master (commit 5dc13c2), pipedv1
  • control-plane version: master
  • Others: N/A
主要语言
Go
星标
1.4k
派生
403
平均合并
2 天 9 小时
30 天内合并 PR
40

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

pipe-cd/pipecd 的其他 Issue

查看 pipe-cd/pipecd 的全部 Issue

相似的 Issue

更多 Go Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。