Skip to content
This repository has been archived by the owner on Jul 22, 2022. It is now read-only.

Issues communicating with agent after closing and re-opening last Terminal #41

Open
BtbN opened this issue May 11, 2022 · 0 comments
Open

Comments

@BtbN
Copy link

BtbN commented May 11, 2022

On the latest Windows 11 Release Preview, the agent communication consistently breaks if I close and re-open the terminal.
ssh-add -l then fails with communication with agent failed.

The strange thing is, it works fine when I initially open the Terminal, and it freshly starts socat.
It also works great if I then open another terminal, while the other is still open.

However, if I close the Terminal, and then re-open it, communication with the agent becomes impossible with the above error.
Killing socat and opening another terminal(re-running the code in zshrc) fixes the issue momentarily, until I close all terminals again.

However again, if I close the Terminal and wait long enough for WSL2 to stop the VM after a minute or so, and then start a new Terminal, a new socat process is started and it works fine.
So this only happens if I somewhat quickly close and re-open the last open Terminal.

In that state, ps lists the socat process just fine, and it also appears in ss output.

I have adapted the snippet in my zshrc to account for that situation:

export SSH_AUTH_SOCK="$HOME/.ssh/agent.sock"
ssh-add -l >/dev/null 2>&1; SSH_RES=$?
ss -a | grep -q "$SSH_AUTH_SOCK"; SS_RES=$?
if [[ $SSH_RES == 1 && $SS_RES == 0 ]]; then
    pkill -f "$SSH_AUTH_SOCK"
    SS_RES=1
fi
if [[ $SS_RES != 0 ]]; then
    rm -f "$SSH_AUTH_SOCK"
    PAGEANT_BIN="$HOME/.ssh/wsl2-ssh-pageant.exe"
    if test -x "$PAGEANT_BIN"; then
        (setsid nohup socat UNIX-LISTEN:"$SSH_AUTH_SOCK,fork" EXEC:"$PAGEANT_BIN" >/dev/null 2>&1 &)
    else
        echo >&2 "WARNING: $PAGEANT_BIN is not executable."
    fi
    unset PAGEANT_BIN
fi
unset SSH_RES SS_RES

But that is merely a workaround, and not an actual fix for the issue.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant