Workbench: Kernel sessions can leak when run in login shells
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- r, shell, typescript
- Domain
- backend, devtools, operating-systems
Research direction
Start by tracing Kallichore's child-process handling for kernels launched through login shells, then inspect ark's SIGTERM behavior. Reproduce the issue by quitting a Workbench session and checking for orphaned ark processes. Done means the shell and inner kernel both exit when the Positron session ends, without leaked processes.
Written by the indexing model from the issue text.
Description
System details:
Positron and OS details:
Positron Version: 2025.07.0 build 74
Code - OSS Version: 1.100.0
Commit: fe621e856f2e66144c97d30a3c77471947048e61
Date: 2025-06-09T03:43:20.444Z
Browser: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36
Interpreter details:
R 4.4.0 (but any R will do)
Describe the issue:
A timing-dependent issue can cause kernel sessions to leak on Workbench when they are run in login shells.
Steps to reproduce the issue:
- Connect to a Workbench instance and start a Positron session
- Start R in the session
- Reload the tab containing the session several times, observe R reconnecting (good)
- Go to your Workbench homepage and quit the session
- Connect to the Workbench instance via another means and check for running
arkprocesses - Observe a zombie R
arkprocess that hasinit(1)as a parent and doesn't respond toSIGTERM
user15@ip-10-0-142-166:~$ kill 45195
user15@ip-10-0-142-166:~$ ps -ef | grep ark | grep user15
user15 45195 1 0 Jun12 ? 00:02:25 /usr/lib/rstudio-server/bin/positron-server/extensions/positron-r/resources/ark/ark --connection_file /tmp/registration_r-c759da0c.json --log /tmp/kernel-dCYtMF/kernel.log --startup-file /usr/lib/rstudio-server/bin/positron-server/extensions/positron-r/resources/scripts/startup.R --session-mode console --default-repos posit-ppm -- --interactive --no-restore-data
Expected or desired behavior:
All ark sessions exit when the Positron session does
This is a regression introduced by the (otherwise useful) feature that runs sessions in login shells. Here is what is happening:
First, the supervisor starts a shell that runs the ark kernel. This means we have two processes for each ark kernel, which is okay. The first is /bin/sh (or whatever the user's shell is) and the other is ark itself.
user16 217130 200751 0 21:33 ? 00:00:00 /bin/sh -l -c /usr/lib/rstudio-server/bin/positron-server/extensions/positron-r/resources/ark/ark --connection_file /tmp/registration_r-079e1f59.json --log /tmp/kernel-a3J1oH/kernel.log --startup-file /usr/lib/rstudio-server/bin/positron-server/extensions/positron-r/resources/scripts/startup.R --session-mode console --default-repos posit-ppm -- --interactive --no-restore-data
user16 217139 217130 0 21:33 ? 00:00:02 /usr/lib/rstudio-server/bin/positron-server/extensions/positron-r/resources/ark/ark --connection_file /tmp/registration_r-079e1f59.json --log /tmp/kernel-a3J1oH/kernel.log --startup-file /usr/lib/rstudio-server/bin/positron-server/extensions/positron-r/resources/scripts/startup.R --session-mode console --default-repos posit-ppm -- --interactive --no-restore-data
When the Positron session exits as a result of the user quitting from the dashboard, SIGTERM is sent to the whole process tree. The result is that Kallichore, the shell, and ark all get SIGTERM at once. Here are the Kallichore logs from one such event:
21:27:26 [INFO] Received SIGTERM signal, initiating graceful shutdown
21:27:26 [INFO] Child process for session r-f433caa4 exited with status: signal: 15 (SIGTERM)
21:27:26 [INFO] Shutting down 1 running sessions
21:27:26 [INFO] All sessions have exited; exiting Kallichore server.
21:27:26 [INFO] Session r-f433caa4 has been asked to shut down
21:
Because /bin/sh is the command Kallichore ran, it thinks the kernel has exited when /bin/sh exits with SIGTERM (line 2 of the logs), and -- since all kernels have exited -- Kallichore itself exits.
But in fact ark is still running, because it appears to ignore SIGTERM in this context.
There are probably 2 fixes needed here:
- The fact that
arkignoresSIGTERM(not only here but also when it iskill'ed) feels like a bug. If ark shut itself down when receiving aSIGTERM, it would not leak. - When running a kernel in a shell, Kallichore should not consider the kernel exited until the inner kernel process has exited, even if the outer shell process has ended.
Even though I think we should make both of those improvements, this issue should mostly not be a problem in practice due to https://github.com/posit-dev/ark/pull/830.
- Dominant language
- TypeScript
- Stars
- 4.3k
- Forks
- 184
- Avg merge
- 1d 9h
- Merged PRs (30d)
- 195
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from posit-dev/positron
-
ci-cd lang: python
Difficulty 1/5 Under an hour Newbie friendliness 84/100
-
area: quarto lang: r
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
area: quarto lang: r
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
-
area: onboarding area: welcome enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
area: assistant bug support
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
All issues in posit-dev/positron
Similar issues
-
clawsweeper:fix-shape-clear clawsweeper:queueable-fix clawsweeper:source-repro impact:ux-friction issue-rating: 🦞 diamond lobster no-stale P3
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
community first-timers-only good first issue hacktoberfest help wanted low hanging fruit up-for-grabs
Difficulty 1/5 Under an hour Newbie friendliness 76/100
-
code-quality refactoring
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
github/gh-aw-firewall#8816 ·
-
integration:quickjs org:external priority:backlog topic:code-interpreter topic:middleware type:feature
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
langchain-ai/deepagents#6450 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
vercel/react-tweet#225 ·