fix(compose): コンテナに init: true を注入してゾンビプロセス蓄積を解消 (#28)#32
Merged
Conversation
devbase コンテナの PID 1 は entrypoint の `tail -f /dev/null` で orphan を
reap しないため、`nohup ... & disown` で起動したプロセスがゾンビ化して蓄積する。
特に cross-review の monitor.py がゾンビを「実行中」と誤判定し hard timeout まで
待たされる二次被害が出る。
generate_scaled_compose() の dev / non-dev 両サービス生成ループで
`setdefault('init', True)` を注入し、docker が tini を PID 1 に挿入するように
する。devbase up は常にこの生成ファイル単独で compose up するため scale=1 でも
網羅される。setdefault のため明示的な `init: false` は尊重する。
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
概要
devbase コンテナの PID 1 は entrypoint の
tail -f /dev/nullであり orphan プロセスを reap しないため、nohup ... & disownで起動・終了したプロセスがゾンビ (<defunct>) 化して蓄積する。特にndf:cross-reviewのmonitor.pyはゾンビに対してもkill -0が成功するため「実行中」と誤判定し、hard timeout (420s) まで待たされる二次被害がある。generate_scaled_compose()が生成する全サービスに Docker Compose のinit: trueを注入し、tini を PID 1 として挿入することでゾンビを自動 reap する。関連 Issue
変更点
lib/devbase/volume/compose.py:generate_scaled_compose()の dev インスタンス複製ループと non-dev サービス複製ループの双方でsetdefault('init', True)を注入setdefaultのため、プロジェクトが明示したinit: falseは尊重して上書きしないdevbase upは常に生成された.docker-compose.scale.yml単独でdocker compose upするため、scale=1 を含む全ケースを網羅 (ベースcompose.ymlの変更不要)tests/volume/test_compose.py(新規): dev/non-dev への注入・scale>1 全インスタンス・init: false尊重を検証動作確認
pytest tests/volume/test_compose.py3件 passpytest tests/全 293件 pass (リグレッションなし)devbase up && devbase login後ps -p 1 -o comm=がtiniを返すnohup sleep 1 & disown; sleep 3; ps aux | grep 'Z.*defunct'がゾンビを出さない補足
挙動の変化は「PID 1 が tini になる」のみで、entrypoint (
tail -f /dev/null) は tini の子プロセスとして従来どおり動作する (後方互換)。PR_SET_CHILD_SUBREAPER方式より単純で確実なため Docker 公式推奨のinit: trueを採用した。