Files
w3cjandClaude Opus 5.5 90a64a44d1 fix(races): lock order checked, sandboxes' own ports, pins that meet a rename, daemons' groups stopped
- state: test builds and tests check the state locks' order (state.held, CheckLockOrder): a second VM's lock, a VM's lock under the claims lock, or a lock taken again panics before waiting.
- platform: PinBeneath opens the path again when a rename takes the file away before move_mount (ENOENT), so the keeper no longer reports a false lost pin (TestPinsInNamespace's 'f lost / f pinned-again'); TestPinWhileRenamed.
- daemon: Proc.Stop signals the process group (SignalGroup), so forwarders' and link sessions' ssh masters and relays end with them; ui.UI.StopsItsOwn makes _ports and _links wait for their ssh on an outside SIGTERM.
- vm: gc --orphans and devvm space count forwarders' leftover control sockets (vmssh.ControlGlob).
- CLI tests: each sandbox claims a block of ports below devvm's range and the ephemeral range (claimPortBlock, /tmp/devvm-test-ports); free_port, the fixtures' ports and DEVVM_SSH_PORTS come from it, and the sandbox's devvm chooses from its own range (DEVVM_PORT_RANGE override). Fixtures' forwarded ports and settings ports are rewritten too (FIXTURE_PORT_<port>).
- netpolicy and vm tests: the fake proxy's stop waits for its reap, and fake daemons run until the test ends, not 30 s.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-15 22:04:31 -07:00

45 lines
1.3 KiB
Go

package cli
import (
"io/fs"
"github.com/spf13/cobra"
"github.com/devvmhq/devvm/assets"
"github.com/devvmhq/devvm/internal/msg"
"github.com/devvmhq/devvm/internal/vmssh"
)
// newForwarderCmd is devvm _ports: a VM's port forwarder (vmssh.Main),
// on every backend, which devvm starts detached (vmssh.Forwards). It
// gets ports.sh and devvm's folders, where it reads the ports it never
// forwards (ports.Reserved); its log lines are data, written to devvm's
// stderr. Hidden: it's not for users. Its flags are the forwarder's own,
// parsed by vmssh.Main. A signal waits for it to stop its ssh master and
// relays (ui.UI.StopsItsOwn).
func newForwarderCmd(a *app) *cobra.Command {
u := a.u
return &cobra.Command{
Use: vmssh.Cmd + " [flags]",
Short: "Forward a VM's ports",
Hidden: true,
DisableFlagParsing: true,
RunE: func(cmd *cobra.Command, args []string) error {
u.StopsItsOwn()
fail := func(err error) error { return msg.ForwarderFailed(err.Error()).Because(err) }
d, err := a.dirs()
if err != nil {
return fail(err)
}
script, err := fs.ReadFile(assets.FS, "guest/ports.sh")
if err != nil {
return fail(err)
}
if err := vmssh.Main(cmd.Context(), args, script, d, u.Stderr()); err != nil {
return fail(err)
}
return nil
},
}
}