GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(mcpx): disposition Codex round-2 findings on the ssh transport (#… · developing-today/code@0a9ee54

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • pkgs/mcpx/internal/cli
    • client.go
    • connect.go
    • ssh_endpoint_test.go
    • stdio_proxy.go
    • stdio_proxy_test.go
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎pkgs/mcpx/internal/cli/client.go‎

Copy file name to clipboardExpand all lines: pkgs/mcpx/internal/cli/client.go
+17-1Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,22 @@ func (c *Client) Ping(ctx context.Context) bool {
407407
return err == nil
408408
}
409409

410+
// reachable is Ping with the ssh:// fallback EnsureDaemon has always had:
411+
// an ssh handshake can legitimately take longer than
412+
// autostart.pingTimeout, so a timed-out Ping is retried once as a plain
413+
// health request bounded only by the caller's ctx before the daemon is
414+
// declared unreachable. Non-ssh endpoints get Ping exactly.
415+
func (c *Client) reachable(ctx context.Context) bool {
416+
if c.Ping(ctx) {
417+
return true
418+
}
419+
if c.ssh == nil {
420+
return false
421+
}
422+
_, err := c.do(ctx, http.MethodGet, "/v1/health", nil)
423+
return err == nil
424+
}
425+
410426
// EnsureDaemon starts a background daemon if one is not already running and
411427
// waits for it to become reachable. This is what makes every command work with
412428
// no setup step.
@@ -422,7 +438,7 @@ func (c *Client) EnsureDaemon(ctx context.Context) error {
422438
// Starting a local daemon because a remote one is unreachable would
423439
// silently answer from the wrong machine, which is worse than
424440
// failing.
425-
if c.Ping(ctx) {
441+
if c.reachable(ctx) {
426442
return nil
427443
}
428444
if err := ctx.Err(); err != nil {
Collapse file

‎pkgs/mcpx/internal/cli/connect.go‎

Copy file name to clipboardExpand all lines: pkgs/mcpx/internal/cli/connect.go
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func (a *App) Connect(ctx context.Context, opt ConnectOptions) (*Client, *Ladder
9292
if opt.Endpoint != "" {
9393
start := time.Now()
9494
c := NewClientAt(paths, a.ConfigPath, opt.Endpoint)
95-
if c.Ping(ctx) {
95+
if c.reachable(ctx) {
9696
record("url", opt.Endpoint, start, nil)
9797
l.Chosen = "url"
9898
return c, l, nil
Collapse file

‎pkgs/mcpx/internal/cli/ssh_endpoint_test.go‎

Copy file name to clipboardExpand all lines: pkgs/mcpx/internal/cli/ssh_endpoint_test.go
+27Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,3 +208,30 @@ func socketPathFor(t *testing.T) string {
208208
t.Helper()
209209
return filepath.Join(t.TempDir(), "should-not-be-used.sock")
210210
}
211+
212+
// The CLI connection ladder gets the same slow-handshake fallback as
213+
// EnsureDaemon: Connect's named-endpoint rung used to Ping once, so a
214+
// first ssh handshake slower than autostart.pingTimeout (2s) made every
215+
// ordinary command report a reachable daemon as dead. The fake ssh
216+
// sleeps 3s on its first invocation only; the fallback health request
217+
// dials again and answers at once.
218+
func TestSSHConnectFallsBackPastSlowHandshake(t *testing.T) {
219+
sock := testSocketServer(t)
220+
t.Setenv("MCPX_TEST_SSH_SOCK", sock)
221+
marker := filepath.Join(t.TempDir(), "ssh.slowed")
222+
t.Setenv("MCPX_TEST_SSH_SLOW", marker)
223+
fakeSSH(t, "#!/bin/sh\n"+
224+
"if [ ! -f \"$MCPX_TEST_SSH_SLOW\" ]; then : > \"$MCPX_TEST_SSH_SLOW\"; sleep 3; fi\n"+
225+
"exec \""+os.Args[0]+"\" -test.run '^TestSSHShimProcess$' -- shim\n")
226+
227+
a := &App{Paths: daemon.Paths{State: t.TempDir(), Socket: socketPathFor(t)}}
228+
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
229+
defer cancel()
230+
c, ladder, err := a.Connect(ctx, ConnectOptions{Endpoint: "ssh://buildbox"})
231+
if err != nil {
232+
t.Fatalf("Connect over a slow ssh handshake: %v\n%s", err, ladder.Describe())
233+
}
234+
if c == nil || ladder.Chosen != "url" {
235+
t.Fatalf("Connect chose %q; want the named ssh endpoint", ladder.Chosen)
236+
}
237+
}
Collapse file

‎pkgs/mcpx/internal/cli/stdio_proxy.go‎

Copy file name to clipboardExpand all lines: pkgs/mcpx/internal/cli/stdio_proxy.go
+14-1Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,20 @@ func (a *App) CmdStdioProxy(ctx context.Context, args []string) error {
5656
}
5757
defer conn.Close()
5858

59-
return pipeConn(conn, os.Stdin, os.Stdout)
59+
return proxyPipe(ctx, conn, os.Stdin, os.Stdout)
60+
}
61+
62+
// proxyPipe pipes between the daemon socket and the session's stdio,
63+
// ending when the caller's ctx does. pipeConn alone blocks in io.Copy
64+
// once dialling is done, so a SIGINT/SIGTERM delivered through main's
65+
// signal.NotifyContext would leave the proxy alive indefinitely on a
66+
// streaming response (the daemon streams /v1/events until the
67+
// connection closes). Closing the socket on cancellation is what makes
68+
// the copy return.
69+
func proxyPipe(ctx context.Context, conn net.Conn, in io.Reader, out io.Writer) error {
70+
stop := context.AfterFunc(ctx, func() { _ = conn.Close() })
71+
defer stop()
72+
return pipeConn(conn, in, out)
6073
}
6174

6275
// pipeConn copies in to conn and conn to out until the far end closes.
Collapse file

‎pkgs/mcpx/internal/cli/stdio_proxy_test.go‎

Copy file name to clipboardExpand all lines: pkgs/mcpx/internal/cli/stdio_proxy_test.go
+22Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,25 @@ func TestStdioProxyNamesTheSocket(t *testing.T) {
7272
}
7373
}
7474
}
75+
76+
// Cancellation ends the proxy even when the daemon never sends another
77+
// byte and never closes: the ctx-triggered socket close is the only
78+
// thing that can interrupt the copy.
79+
func TestProxyPipeStopsOnContextCancel(t *testing.T) {
80+
client, server := net.Pipe()
81+
defer server.Close()
82+
83+
ctx, cancel := context.WithCancel(context.Background())
84+
done := make(chan error, 1)
85+
go func() {
86+
done <- proxyPipe(ctx, client, strings.NewReader(""), io.Discard)
87+
}()
88+
89+
time.Sleep(100 * time.Millisecond)
90+
cancel()
91+
select {
92+
case <-done:
93+
case <-time.After(5 * time.Second):
94+
t.Fatal("proxyPipe kept piping after its context was cancelled")
95+
}
96+
}

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.