Skip to content

PTY handle leaks #15592

@kikuchan

Description

@kikuchan

Description

When I try to run a lot of commands via PTY endpoint, it leaks file handle and got an error: out of resource.

If a process spawned by using the endpoint exits before a call of DELETE /pty{ptyID} endpoint, it doesn't close its file handle at all.
If the process is killed by the call of DELETE, it cleans up the file handle properly.

Plugins

none

OpenCode version

latest

Steps to reproduce

  1. Run opencode web to open a web interface
  2. Open a terminal in the web interface
  3. Type exit to exit the shell
  4. repeat 2-3, 100 times.
  5. run lsof -p against the opencode process id, it shows 300 file handles of the pty.

Screenshot and/or share link

opencode 2974423 kikuchan 1973u CHR 136,485 0t0 488 /dev/pts/485
opencode 2974423 kikuchan 1974u CHR 5,2 0t0 138 /dev/ptmx
opencode 2974423 kikuchan 1975u CHR 5,2 0t0 138 /dev/ptmx
opencode 2974423 kikuchan 1976u CHR 136,486 0t0 489 /dev/pts/486
opencode 2974423 kikuchan 1977u CHR 5,2 0t0 138 /dev/ptmx
opencode 2974423 kikuchan 1978u CHR 5,2 0t0 138 /dev/ptmx
opencode 2974423 kikuchan 1979u CHR 5,2 0t0 138 /dev/ptmx
opencode 2974423 kikuchan 1980u CHR 136,487 0t0 490 /dev/pts/487
opencode 2974423 kikuchan 1981u CHR 5,2 0t0 138 /dev/ptmx
opencode 2974423 kikuchan 1982u CHR 5,2 0t0 138 /dev/ptmx
opencode 2974423 kikuchan 1983u CHR 5,2 0t0 138 /dev/ptmx
opencode 2974423 kikuchan 1984u CHR 136,488 0t0 491 /dev/pts/488
opencode 2974423 kikuchan 1985u CHR 5,2 0t0 138 /dev/ptmx
opencode 2974423 kikuchan 1986u CHR 5,2 0t0 138 /dev/ptmx
opencode 2974423 kikuchan 1987u CHR 5,2 0t0 138 /dev/ptmx
opencode 2974423 kikuchan 1988u CHR 136,489 0t0 492 /dev/pts/489
opencode 2974423 kikuchan 1989u CHR 5,2 0t0 138 /dev/ptmx
opencode 2974423 kikuchan 1990u CHR 5,2 0t0 138 /dev/ptmx
opencode 2974423 kikuchan 1991u CHR 5,2 0t0 138 /dev/ptmx
opencode 2974423 kikuchan 1992u CHR 136,490 0t0 493 /dev/pts/490
opencode 2974423 kikuchan 1993u CHR 5,2 0t0 138 /dev/ptmx
opencode 2974423 kikuchan 1994u CHR 5,2 0t0 138 /dev/ptmx
opencode 2974423 kikuchan 1995u CHR 5,2 0t0 138 /dev/ptmx
opencode 2974423 kikuchan 1996u CHR 136,491 0t0 494 /dev/pts/491
opencode 2974423 kikuchan 1997u CHR 5,2 0t0 138 /dev/ptmx
opencode 2974423 kikuchan 1998u CHR 5,2 0t0 138 /dev/ptmx
opencode 2974423 kikuchan 1999u CHR 5,2 0t0 138 /dev/ptmx
opencode 2974423 kikuchan 2000u CHR 136,492 0t0 495 /dev/pts/492
opencode 2974423 kikuchan 2001u CHR 5,2 0t0 138 /dev/ptmx
opencode 2974423 kikuchan 2002u CHR 5,2 0t0 138 /dev/ptmx
opencode 2974423 kikuchan 2003u CHR 5,2 0t0 138 /dev/ptmx
opencode 2974423 kikuchan 2004u CHR 136,493 0t0 496 /dev/pts/493
opencode 2974423 kikuchan 2005u CHR 5,2 0t0 138 /dev/ptmx
opencode 2974423 kikuchan 2006u CHR 5,2 0t0 138 /dev/ptmx
opencode 2974423 kikuchan 2007u CHR 5,2 0t0 138 /dev/ptmx
opencode 2974423 kikuchan 2008u CHR 136,494 0t0 497 /dev/pts/494
opencode 2974423 kikuchan 2009u CHR 5,2 0t0 138 /dev/ptmx
opencode 2974423 kikuchan 2010u CHR 5,2 0t0 138 /dev/ptmx
opencode 2974423 kikuchan 2011u CHR 5,2 0t0 138 /dev/ptmx
opencode 2974423 kikuchan 2012u CHR 136,495 0t0 498 /dev/pts/495
opencode 2974423 kikuchan 2013u CHR 5,2 0t0 138 /dev/ptmx
opencode 2974423 kikuchan 2014u CHR 5,2 0t0 138 /dev/ptmx
opencode 2974423 kikuchan 2015u CHR 5,2 0t0 138 /dev/ptmx
opencode 2974423 kikuchan 2016u CHR 136,496 0t0 499 /dev/pts/496
opencode 2974423 kikuchan 2017u CHR 5,2 0t0 138 /dev/ptmx
opencode 2974423 kikuchan 2018u CHR 5,2 0t0 138 /dev/ptmx
opencode 2974423 kikuchan 2019u CHR 5,2 0t0 138 /dev/ptmx
opencode 2974423 kikuchan 2020u CHR 136,497 0t0 500 /dev/pts/497
opencode 2974423 kikuchan 2021u CHR 5,2 0t0 138 /dev/ptmx
opencode 2974423 kikuchan 2022u CHR 5,2 0t0 138 /dev/ptmx
opencode 2974423 kikuchan 2023u CHR 5,2 0t0 138 /dev/ptmx
opencode 2974423 kikuchan 2024u CHR 136,498 0t0 501 /dev/pts/498
opencode 2974423 kikuchan 2025u CHR 5,2 0t0 138 /dev/ptmx
opencode 2974423 kikuchan 2026u CHR 5,2 0t0 138 /dev/ptmx
opencode 2974423 kikuchan 2027u CHR 5,2 0t0 138 /dev/ptmx
opencode 2974423 kikuchan 2028u CHR 136,499 0t0 502 /dev/pts/499
opencode 2974423 kikuchan 2029u CHR 5,2 0t0 138 /dev/ptmx
opencode 2974423 kikuchan 2030u CHR 5,2 0t0 138 /dev/ptmx

Operating System

Arch Linux

Terminal

No response

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingcoreAnything pertaining to core functionality of the application (opencode server stuff)perfIndicates a performance issue or need for optimization

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions