Files
w3cjandClaude Opus 5.5 ae77c7bc45 fix(daemon): a stopped process counts as stopped once it's gone, not once its arguments go
A proxy restarted on a running VM (its company proxy settings changed,
say) was stopped with SIGTERM, and Proc.Stop took it as stopped as soon
as its arguments could no longer be read. An ending process loses its
memory before its files: on macOS kern.procargs2 fails some milliseconds
before its listening socket closes (every time, in a test of 30 stops),
and on Linux /proc/PID/cmdline reads empty. When Stop looked in that
window, Prepare found the VM's proxy port still taken, failed the launch
with proxy_port_taken and stopped the VM (Unproxied): e2e's company
proxy checks 15 and 17 failed in turn, and the checks after them found
the VM stopped.

- daemon.Proc.Stop waits until no process has the pid, or another
  process does (Proc.ended); one whose arguments can't be read is still
  ending.
- platform.ProcessArgs on Linux returns an error for an empty cmdline
  (an ending or unreaped process), as macOS does, never [""].
- Tests: TestProcStopWaitsForTheEnd (fails before the fix: Stop returned
  while the process still ran) and TestProcessArgsEnded.
- e2e: check prints a failed check's "failed: " lines first, then its
  last lines (5, or check_lines); checks 15 and 17 are functions
  (corp_through, corp_direct) whose steps each name themselves, then
  corp_why shows the VM's status, its proxy, the launch's output, the
  proxy's log and events, and the company proxy's log and events.
- docs: internals/network.md says when the old proxy counts as stopped.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-02 22:46:56 -07:00

23 lines
584 B
Go

package platform
import (
"errors"
"os"
"strconv"
"strings"
)
// ProcessArgs returns a running process's arguments, its program's name
// first, from /proc. One that's ending, or ended and not yet reaped, has
// none there: an error, as on macOS.
func ProcessArgs(pid int) ([]string, error) {
b, err := os.ReadFile("/proc/" + strconv.Itoa(pid) + "/cmdline")
if err != nil {
return nil, err
}
if len(b) == 0 {
return nil, errors.New("no arguments: the process is ending, or a kernel thread")
}
return strings.Split(strings.TrimSuffix(string(b), "\x00"), "\x00"), nil
}