{"record":{"id":"bf18668ae862de18","repo":"kovidgoyal/kitty","slug":"setup-of-port-forward-in-ssh-controlmaster-failed","errorCode":null,"errorMessage":"Setup of port forward in SSH ControlMaster failed with error: invalid resolved port returned: %s","messagePattern":"Setup of port forward in SSH ControlMaster failed with error: invalid resolved port returned: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kittens/ssh/main.go","lineNumber":752,"sourceCode":"\t\t}\n\t\tif protocol == \"unix\" && strings.HasPrefix(listen_on, \"@\") {\n\t\t\treturn 1, fmt.Errorf(\"Cannot forward kitty remote control socket when an abstract UNIX socket (%s) is used, due to limitations in OpenSSH. Use either a path based one or a TCP socket\", listen_on)\n\t\t}\n\t\tcmcmd := slices.Clone(cmd[:insertion_point])\n\t\tcmcmd = append(cmcmd, control_master_args...)\n\t\tcmcmd = append(cmcmd, \"-R\", \"0:\"+listen_on, \"-O\", \"forward\")\n\t\tcmcmd = append(cmcmd, \"--\", hostname)\n\t\tc := exec.Command(cmcmd[0], cmcmd[1:]...)\n\t\tb := bytes.Buffer{}\n\t\tc.Stdout = &b\n\t\tc.Stderr = os.Stderr\n\t\tif err := c.Run(); err != nil {\n\t\t\treturn 1, fmt.Errorf(\"%s\\nSetup of port forward in SSH ControlMaster failed with error: %w\", b.String(), err)\n\t\t}\n\t\tport, err := strconv.Atoi(strings.TrimSpace(b.String()))\n\t\tif err != nil {\n\t\t\tos.Stderr.Write(b.Bytes())\n\t\t\treturn 1, fmt.Errorf(\"Setup of port forward in SSH ControlMaster failed with error: invalid resolved port returned: %s\", b.String())\n\t\t}\n\t\tcd.listen_on = \"tcp:localhost:\" + strconv.Itoa(port)\n\t}\n\tterm, err := tty.OpenControllingTerm(tty.SetNoEcho)\n\tif err != nil {\n\t\treturn 1, fmt.Errorf(\"Failed to open controlling terminal with error: %w\", err)\n\t}\n\tcd.echo_on = term.WasEchoOnOriginally()\n\tcd.host_opts, cd.literal_env = host_opts, literal_env\n\tcd.request_data = need_to_request_data\n\tcd.hostname_for_match, cd.username = hostname_for_match, uname\n\tescape_codes_to_set_colors, err := change_colors(cd.host_opts.Color_scheme)\n\tif err == nil {\n\t\terr = term.WriteAllString(escape_codes_to_set_colors + loop.SAVE_PRIVATE_MODE_VALUES + loop.PUSH_KEY_FLAGS + loop.HANDLE_TERMIOS_SIGNALS.EscapeCodeToSet())\n\t}\n\tif err != nil {\n\t\treturn 1, err\n\t}","sourceCodeStart":734,"sourceCodeEnd":770,"githubUrl":"https://github.com/kovidgoyal/kitty/blob/6d5d0c440603ad9bdf6dcd599f73f6dde21acb44/kittens/ssh/main.go#L734-L770","documentation":"After a successful ssh -R 0:... -O forward, ssh is expected to print the dynamically allocated listening port on stdout. strconv.Atoi on that output failed, meaning ssh printed something that isn't a number (or nothing).","triggerScenarios":"ssh -O forward succeeds (exit 0) but stdout is empty or non-numeric — older OpenSSH versions that don't report the allocated port, or extra output polluting stdout.","commonSituations":"Very old OpenSSH clients (< 7.x) lacking '-R 0' port reporting; ssh wrappers or banners writing to stdout; patched/distrowrapped ssh binaries.","solutions":["Check OpenSSH client version; upgrade to a modern version (>= 7.6, ideally 8+)","Ensure no wrapper script/banner writes extra text to ssh stdout","Reproduce manually: ssh -O forward -R 0:<socket> <host> and inspect what is printed"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":"ssh -V 2>&1  # require OpenSSH >= 7.6 before enabling forward_remote_control","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use a recent OpenSSH client","Don't wrap ssh in scripts that print to stdout"],"tags":["kitty","ssh","port-parsing","openssh-version"],"backgroundTag":"unexpected-command-output-format","analyzedSha":"6d5d0c440603ad9bdf6dcd599f73f6dde21acb44","analyzedAt":"2026-08-27T14:20:20.142Z","schemaVersion":2},"datasetVersion":"2026-08-27T19:17:21.184Z"}