The Gateway page, `magpie serve` and the app log said only "port N is held by another program". pluoki's was `tailscale serve` on the same port number. proc.PortHolder reads the holder (lsof on the Mac, /proc on Linux, Get-NetTCPConnection on Windows). Tailscale's daemon is root's and often unreadable, so `tailscale serve status --json` is the fallback for the port. gateway.NoteHeld / PortHeld.Sentence say who holds it, and for Tailscale give `tailscale serve --https=<other> http://127.0.0.1:<port>`. Shown in the `magpie serve` standby line and bind error, the app log, `gatewayHeld` in /api/state (Gateway page) and Start's "taken" answer, in en, zh, zh-TW, ja, de. A holder that can't be read says nothing; the old wording stands. Nothing is killed or touched. Run: gofmt clean; go vet darwin, linux nogui, windows (mica); go test ./internal/proc ok; targeted holder/gateway tests on macOS (mica), Windows (win-run) and Linux (wsl-run); parser tests with real lsof output; GUI gateway-port-holder, gateway-takeover, gateway-older, gateway-skew, gateway-port, i18n-keys, i18n-en-no-cjk in chromium and webkit. Real run on WSL: a holder named tailscaled on the LAN address with magpie on 0.0.0.0 gives the Tailscale sentence at the bind error; a Python holder on loopback gives "held by python3.12 (pid N)". Broken by hand: each fix reverted in turn, its test went red. gateway-card.test.cjs is red on origin/main too (#6029). internal/gateway, gui and cli package runs were still going at push; the full suite follows the tag. Not tried: a real `tailscale serve` (changes live config), a real Windows holder end to end, the bind-error path on macOS (a wildcard bind coexists with a specific one there).
49 lines
1.2 KiB
Go
49 lines
1.2 KiB
Go
package proc
|
|
|
|
import (
|
|
"fmt"
|
|
"io"
|
|
"net"
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/yetone/magpie/internal/testenv"
|
|
)
|
|
|
|
// The tests run in a home of their own, never the user's real files.
|
|
// With MAGPIE_PROC_RAN set, the test binary stands in for a program a
|
|
// probe asks its version (guiexe_windows_test.go): it notes that it was
|
|
// started there and answers.
|
|
//
|
|
// With MAGPIE_PROC_SLEEP set, it runs until its stdin closes
|
|
// (listener_test.go).
|
|
//
|
|
// With MAGPIE_PROC_LISTEN set to an address, it listens there first, says
|
|
// "listening" and then runs the same way (holder_test.go).
|
|
func TestMain(m *testing.M) {
|
|
if addr := os.Getenv("MAGPIE_PROC_LISTEN"); addr != "" {
|
|
ln, err := net.Listen("tcp", addr)
|
|
if err != nil {
|
|
fmt.Println("error", err)
|
|
os.Exit(1)
|
|
}
|
|
defer ln.Close()
|
|
fmt.Println("listening")
|
|
io.Copy(io.Discard, os.Stdin)
|
|
os.Exit(0)
|
|
}
|
|
if os.Getenv("MAGPIE_PROC_SLEEP") != "" {
|
|
io.Copy(io.Discard, os.Stdin)
|
|
os.Exit(0)
|
|
}
|
|
if ran := os.Getenv("MAGPIE_PROC_RAN"); ran != "" {
|
|
if f, err := os.OpenFile(ran, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0o644); err == nil {
|
|
fmt.Fprintln(f, os.Args[0])
|
|
f.Close()
|
|
}
|
|
fmt.Println("2.2.5")
|
|
os.Exit(0)
|
|
}
|
|
testenv.Main(m)
|
|
}
|