Shell Corruption After Exiting IEx with Node.js Port

I’ve encountered an issue where my zsh shell becomes corrupted after exiting IEx, and I’ve traced it to a port that run a Node.js executable in elixir-nodejs/lib/nodejs/worker.ex at master · revelrylabs/elixir-nodejs · GitHub . This can be reproduced with the following steps in IEx:

iex
Erlang/OTP 26 [erts-14.1.1] [source] [64-bit] [smp:24:24] [ds:24:24:10] [async-threads:1] [jit:ns]

Interactive Elixir (1.16.0) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> node = System.find_executable("node")
"/home/mrdotb/.local/share/mise/installs/node/20.1.0/bin/node"
iex(2)> Port.open({:spawn_executable, node}, line: 100)
#Port<0.4>

When I quit IEx after this, the shell doesn’t fully restore, leaving my zsh session in a corrupted state.

What I’ve Tried

  • Killing the port with Port.kill before quitting IEx, which restores the shell properly.
  • Attempting to pass various environment variables to the Node.js process, like NODE_DISABLE_COLORS, TERM=dummy, but without success.
  • Wrapping iex in a subshell at the end the subshell is corrupted but it exit immediatly.

What’s the proper way to solve this issue ?

2 Likes