Repository navigation
fix(interactive)!: let a managed arf remove its IPC socket and session registration when its agent closes - #1991
Conversation
… registration when its agent closes Closing an agent sent SIGKILL to the arf it had started, so arf could not remove its IPC socket and its session registration. This happened when the agent closed after its last client left, on SIGTERM or SIGINT, and when it failed to start. Closing now ends a managed arf as Stop does, within one deadline. arf is asked to shut down over IPC on a connection that reaches the arf that was started, waiting briefly for its endpoint if arf is still starting. If IPC cannot be used, arf receives SIGTERM on Linux and macOS, where Node can only terminate it forcibly on Windows. arf that has not exited after its grace period is killed. The backend removes its runtime files only after arf has exited, and an agent that receives SIGTERM or SIGINT again while closing keeps waiting. An adopted arf is still never asked to shut down or sent a signal when its agent closes.
renkun-ken
left a comment
There was a problem hiding this comment.
The direct-launch cleanup tests passed on macOS with arf 0.7.2. I’m requesting changes because I reproduced a managed R process surviving agent close with a configured launcher, and the repeated-signal test also passed with the old one-shot handler restored. The inline comments cover the process identity, cleanup ordering, and test changes.
…firm its exit before removing its files A managed arf was verified on its first attach only by its session ID, which that attach recorded, so a socket path served by another arf at that moment could be accepted, and closing would ask that arf to shut down. The PID in arf's readiness record now identifies it: every attach, including one made while closing during startup, must report that PID. This also lets closing shut down over IPC an arf that the configured executable launches as its child. The exit of R is confirmed only once the started process has exited and the PID that arf reported no longer exists. The exit of a launcher alone no longer ends the session or completes Stop or closing. Signals still go only to the started process, since a PID it did not start may have been reused. A backend whose managed R exit cannot be confirmed now keeps its runtime files, which that R may still use. The test of a second SIGTERM during closing now holds R in a cell until both signals were sent, and probes arf before R is busy, so that it fails with a one-shot signal handler.
renkun-ken
left a comment
There was a problem hiding this comment.
The readiness PID now identifies the responder on the first attach, the backend retains its directory when disposal rejects, and the repeated-signal test fails with the old one-shot handler restored. All 77 backend tests and five focused real-R tests passed locally. I’m requesting changes because I could still make close report success while a wrapped arf was starting, and I could leave a running session stuck in stopping after its IPC endpoint became available again.
Supporting a launcher that starts arf as another process meant tracking a second PID: deferring the launcher's exit, probing a PID that may have been reused, and deciding when Stop may be retried. Each of these had its own races and kept adding cases. r.interactive.arfPath must now be arf itself, or a script that replaces itself with arf using exec. When arf reports another PID than the process that was started, the managed session fails to start with an error that says so, and its disposal reports that the exit of that arf is unconfirmed, keeping the runtime files. Signals and exit confirmation concern only the started process, and every attach must report its PID. The documentation of the setting and the R Interactive guide say which executables are supported. BREAKING CHANGE: a launcher that starts arf as another process, such as a shell script that runs arf without exec, can no longer start a managed session.
|
@renkun-ken Launcher support is removed in 4796db6 instead of being patched further. All three findings in this review come from following a second process: the launcher exiting before readiness, reuse of the launched arf's PID, and Stop recovery through a wrapper. Each fix in that direction has exposed another race, and supporting it would keep this lifecycle code a source of bugs. It should not be supported.
Launcher configurations are out of scope, here and in follow-ups. Please limit further review of this PR to the direct-launch behavior. |
renkun-ken
left a comment
There was a problem hiding this comment.
Approved at 4796db6. Requiring managed sessions to start arf itself, directly or through exec, resolves my earlier launcher findings. The setting and guide document the compatibility change, and the regression test checks the diagnostic for a launcher that reports a different PID.
I tested both supported forms on macOS with arf 0.7.2. Closing an idle session, closing after its IPC socket became unavailable, and closing while R was still in its startup profile all terminated the owned PID and left its registry empty. I also verified that closing an adopted session leaves arf running. All 75 backend tests and five focused real-R tests passed locally.
When an agent closed, it sent SIGKILL to the arf it had started. arf then could not remove its IPC socket and its session registration, which were left behind. This happened when the agent closed after its last client left, when it received SIGTERM or SIGINT, and when it failed to start.
Closing now ends a managed arf as Stop does:
An adopted arf is still never asked to shut down or sent a signal when its agent closes.
Supported arf executables
r.interactive.arfPathmust name arf itself, or a script that replaces itself with arf usingexec. A launcher that starts arf as another process and waits for it is not supported, and a managed session now refuses it: when arf reports another PID than the process that was started, the session fails to start with an error that asks to change the setting, and its disposal reports that the exit of that arf is unconfirmed. Signals and exit confirmation concern only the started process.This is a breaking change for such launchers, which is acceptable while R Interactive is experimental. On main such a launcher could start a session, but closing then waited for the launcher rather than arf. Following a second process instead would require deferring the launcher's exit, probing a PID that may have been reused, and deciding when Stop may be retried, which is not worth supporting. The setting's description and the R Interactive guide state the supported forms.