Skip to content

REPL - fix daemon port parsing#3524

Open
kbrock wants to merge 1 commit intosonic-pi-net:devfrom
kbrock:fix-repl-gem-env
Open

REPL - fix daemon port parsing#3524
kbrock wants to merge 1 commit intosonic-pi-net:devfrom
kbrock:fix-repl-gem-env

Conversation

@kbrock
Copy link
Copy Markdown

@kbrock kbrock commented Apr 15, 2026

Summary

  • Clear GEM_PATH and GEM_HOME when spawning the daemon to prevent Ruby gem warnings from corrupting the stdout port protocol
  • Also clear them at the top of daemon.rb to protect the GUI launch path (e.g. if set via launchctl setenv)

Motivation

When a Ruby version manager (chruby, rbenv, rvm) or system-wide env config sets GEM_PATH/GEM_HOME, the daemon's Ruby process prints "Ignoring ... because its extensions are not built" warnings on startup. Since popen2e merges stdout and stderr, these warnings become the first line read by the port parser, causing all ports to resolve to 0 and crashing with Errno::EADDRNOTAVAIL.

This likely affects some of the reported "GUI unable to connect" issues as well (#3371, #3340, #3270).

Before / After

Before: REPL crashes with Can't assign requested address - connect(2) for "localhost" port 0 when any Ruby version manager is active.

After: Daemon and REPL boot cleanly regardless of host gem environment.

Test plan

  • Set GEM_HOME and GEM_PATH to a directory with gems built for a different Ruby version
  • Run repl.rb — should boot and reach the >> prompt
  • Unset the env vars and run again — should still boot (no regression)

When `GEM_PATH` or `GEM_HOME` are set (e.g. via chruby, rbenv, or
launchctl), Ruby prints "Ignoring..." warnings on startup. Since
`popen2e` merges stdout and stderr, these warnings corrupt the
daemon's port line, causing all ports to parse as 0.

Before: REPL crashes with `Errno::EADDRNOTAVAIL` for port 0 when any
Ruby version manager is active.
After: Daemon and REPL boot cleanly regardless of host gem environment.
@kbrock kbrock changed the title REPL - Clear host gem environment to fix daemon port parsing REPL - fix daemon port parsing Apr 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant