Skip to content

Detect parent process death via stdin EOF#1423

Merged
trungutt merged 2 commits intodocker:mainfrom
trungutt:detect-parent-death
Jan 20, 2026
Merged

Detect parent process death via stdin EOF#1423
trungutt merged 2 commits intodocker:mainfrom
trungutt:detect-parent-death

Conversation

@trungutt
Copy link
Copy Markdown
Contributor

When cagent is spawned by a parent process with piped stdio, monitor stdin for EOF to detect when the parent dies. This ensures cagent shuts down gracefully instead of becoming an orphan process.

When cagent is spawned by a parent process with piped stdio, monitor
stdin for EOF to detect when the parent dies. This ensures cagent
shuts down gracefully instead of becoming an orphan process.
@trungutt trungutt requested a review from a team as a code owner January 19, 2026 16:44
Comment thread cmd/root/api.go
func monitorStdin(cancel context.CancelFunc, stdin *os.File) {
buf := make([]byte, 1)
for {
n, err := stdin.Read(buf)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: could this block the goroutine in other scenarios like normal shutdown if we don't check if the context has already been cancelled? probably not a big issue though since the proc should die anyway in most other scenarios

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I pushed a second commit

Pass context to monitorStdin and close stdin when context is cancelled.
This unblocks the read and allows clean goroutine exit during normal
shutdown (e.g., SIGTERM), not just when the parent process dies.
@trungutt trungutt requested a review from krissetto January 19, 2026 19:12
@trungutt trungutt merged commit e0a04a9 into docker:main Jan 20, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants