Files
w3cjandClaude Opus 5.5 c601958355 fix(links): link sessions' and port forwarders' ssh get devvm's limit on open files
A link session carries up to 256 connections at once through an ssh
master to each target, which takes in two descriptors (stdin, stdout)
for each connection's ssh -W. Go raises devvm's own soft limit on open
files but gives the processes it starts the one it started with, 256 by
default on macOS (and for launchd jobs, as the remote e2e runs are), so
the master ran out of descriptors well before 256 connections
("mm_receive_fd: recvmsg: Message too long") and closed those it
couldn't take: e2e's 256-connection check failed,
and as it returned early it left its link to db:47241 in place, so the
group checks after it found other links than they expected. A shell
with a higher limit (this Mac's) never showed it.

- platform.ShareFileLimit sets the limit to what it is now, so the
  processes devvm starts from then on get it; vmssh.Links.Run and
  vmssh.Forwarder.Run call it first. TestShareFileLimit starts a child
  test at a soft limit of 256 and checks its own child gets more (fails
  without it: 256).
- e2e: the link section runs devvm at a soft limit of 256, so it fails
  without the fix on any Mac (it did, deterministically, on this one).
  lk_cap ends its hold server and removes its link whatever came of its
  checks, and shows the reasons of its refusals. lk_start waits until the helper listens or has ended (its
  wrapper writes "exited N"), and on a failure says so with "failed: ",
  lists its files, shows its output and the VM's TCP listeners. gp_join
  publishes and starts its server, then the three join whatever came of
  the server (gp_joined), so a server that doesn't start fails that
  check alone.
- docs: internals/ports.md (the ssh processes' limit), contributing
  (the link section's limit).

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

57 lines
1.6 KiB
Go

//go:build unix
package platform
import (
"os"
"os/exec"
"strconv"
"strings"
"testing"
)
// fileLimitChild, set in the environment, makes TestShareFileLimit the
// child it starts: started with a soft limit of 256 open files (macOS's
// default), it shares its own limit and logs the one its child gets.
const fileLimitChild = "DEVVM_PLATFORM_TEST_FILE_LIMIT_CHILD"
// A process started with a low soft limit, which Go raises for itself,
// gives the processes it starts its raised limit once it shares it: an ssh
// master carrying 256 connections needs more than 256 descriptors.
func TestShareFileLimit(t *testing.T) {
if os.Getenv(fileLimitChild) != "" {
if err := ShareFileLimit(); err != nil {
t.Fatal(err)
}
out, err := exec.CommandContext(t.Context(), "sh", "-c", "ulimit -S -n").Output()
if err != nil {
t.Fatal(err)
}
t.Logf("child-limit=%s", out)
return
}
self, err := os.Executable()
if err != nil {
t.Fatal(err)
}
cmd := exec.CommandContext(t.Context(), "sh", "-c", //nolint:gosec // the test binary itself
`ulimit -S -n 256 && exec "$0" -test.v -test.run='^TestShareFileLimit$'`, self)
cmd.Env = append(os.Environ(), fileLimitChild+"=1")
out, err := cmd.CombinedOutput()
if err != nil {
t.Fatalf("%v: %s", err, out)
}
_, after, ok := strings.Cut(string(out), "child-limit=")
if !ok {
t.Fatalf("no limit printed: %s", out)
}
first, _, _ := strings.Cut(after, "\n")
n, err := strconv.Atoi(strings.TrimSpace(first))
if first == "unlimited" {
n, err = 1<<31-1, nil
}
if err != nil || n <= 256 {
t.Errorf("the child's soft limit is %q, want more than 256", first)
}
}