Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make sure console master tty is closed on task exit #11161

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

henry118
Copy link
Member

@henry118 henry118 commented Dec 14, 2024

Fixes: #11160

@henry118 henry118 force-pushed the ttyleak branch 2 times, most recently from c448293 to 4dd66e1 Compare December 14, 2024 05:47
@henry118 henry118 force-pushed the ttyleak branch 3 times, most recently from d2728aa to dfc8bd6 Compare December 17, 2024 02:32
@henry118 henry118 changed the title make sure console master tty is closed [WIP] make sure console master tty is closed Dec 17, 2024
@henry118 henry118 force-pushed the ttyleak branch 2 times, most recently from dfc8bd6 to 8a238f6 Compare December 17, 2024 17:50
@henry118 henry118 changed the title [WIP] make sure console master tty is closed make sure console master tty is closed Dec 17, 2024
@henry118 henry118 force-pushed the ttyleak branch 8 times, most recently from ad49a39 to e593ccd Compare December 18, 2024 20:50
@henry118 henry118 changed the title make sure console master tty is closed make sure console master tty is closed on task exit Dec 18, 2024
@@ -276,6 +276,12 @@ func (p *Init) setExited(status int) {
p.exited = time.Now()
p.status = status
p.Platform.ShutdownConsole(context.Background(), p.console)
// We need to close the master tty here, in case of stdin,
Copy link
Member

Choose a reason for hiding this comment

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

I think we can call p.console.Close() during deleting.

func (p *Init) delete(ctx context.Context) error {
waitTimeout(ctx, &p.wg, 2*time.Second)
err := p.runtime.Delete(ctx, p.id, nil)

Before deleting task, containerd always drains IO first. It's safe to close console in that place.

For the line 283 about calling p.wg.Wait(), I think it's unsafe to do that because SetExited is called by background goroutine triggered by SIGCHILD. When init process exits, its children might hold IO so that p.wg.Wait() will block until all its children exit. Check this issue #10094 for more details.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks @fuweid. That info really helped! I've made the suggested changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Console TTY leak in runc shim
3 participants