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

オープン 初心者向け
#7,642 コメント 2 件 リアクション 0 件 担当者 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() を読んで、チャネルと atomic.String がどのように設定されるかを確認してください。送信経路を sync.Once でガードし(先にシグナルを設定してキャンセルし、その後で正確に一度だけ送信して閉じる)、pkg/app/pipedv1/controller/scheduler.go:370-395 のコンシューマーが依然として 1 つの値を受け取ることを確認してください。レポートにある TestStopSignal_Idempotency ケースを controller パッケージのテストに追加し、go test ./pkg/app/pipedv1/controller/... を実行してください。完了とは、繰り返しまたは同時の呼び出しが panic を起こさず、チャネルが一度だけ閉じられることです。

索引モデルが 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時間
マージ済み PR(30日)
40

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

pipe-cd/pipecd のほかの issue

pipe-cd/pipecd の issue をすべて見る

似ている issue

Go の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。