Workbench: Kernel sessions can leak when run in login shells

Open
#8,115 1 comment 0 reactions 0 assignees View on GitHub

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

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

area: kallichore area: workbench lang: r

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:

  1. Connect to a Workbench instance and start a Positron session
  2. Start R in the session
  3. Reload the tab containing the session several times, observe R reconnecting (good)
  4. Go to your Workbench homepage and quit the session
  5. Connect to the Workbench instance via another means and check for running ark processes
  6. Observe a zombie R ark process that has init(1) as a parent and doesn't respond to SIGTERM
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 ark ignores SIGTERM (not only here but also when it is kill'ed) feels like a bug. If ark shut itself down when receiving a SIGTERM, 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from posit-dev/positron

All issues in posit-dev/positron

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.