podman icon indicating copy to clipboard operation
podman copied to clipboard

win-sshproxy fails with WSAEADDRINUSE (bind: Only one usage of each socket address is normally permitted) when restarting Podman machine on Windows

Open ReluPercan opened this issue 1 month ago • 22 comments

Issue Description

On Windows, when starting a Podman machine (podman machine start) after a previous shutdown, reboot, or non-clean termination, win-sshproxy.exe fails to start with the following error logged in Windows Event Viewer:

[error] podman-machine-default: Error occurred in execution group: error listening on socket: /%TEMP%/podman/podman-machine-default-api.sock: listen unix %TEMP%/podman/podman-machine-default-api.sock: bind: Only one usage of each socket address (protocol/network address/port) is normally permitted.

As a result, podman machine start fails or the API forwarding proxy exits immediately.

Root Cause

Unlike Linux, where Go's net.Listen("unix", path) removes/unlinks dead/stale socket files automatically, on Windows (Winsock AF_UNIX), if the .sock file already exists on the filesystem from a previous run, bind() fails with WSAEADDRINUSE (error code 10048).

In win-sshproxy (within containers/gvisor-tap-vsock / containers/podman), net.Listen("unix", path) is called without first unlinking/deleting any leftover socket file at that path.

Steps to reproduce the issue

  1. Run podman machine start (first start succeeds and creates %TEMP%\podman\podman-machine-default-api.sock).
  2. Stop the machine or restart Windows without manual cleanup.
  3. Observe that %TEMP%\podman\podman-machine-default-api.sock (0 bytes) remains on disk.
  4. Run podman machine start again.
  5. win-sshproxy fails with bind: Only one usage of each socket address (protocol/network address/port) is normally permitted.

Describe the results you received

podman machine start fails with WSAEADDRINUSE error from win-sshproxy.exe.

Describe the results you expected

win-sshproxy.exe should either remove/unlink any existing stale .sock file prior to calling net.Listen("unix", path) or overwrite it, allowing the machine to start normally across restarts.

podman info output

Client:
  APIVersion: 6.1.4
  Built: 1791838521
  BuiltTime: Mon Oct 12 23:55:21 2026
  GitCommit: 464c15fec06f0074c916f9eff87c4806869c2833
  GoVersion: go1.26.8
  Os: windows
  OsArch: windows/amd64
  Version: 6.1.4
host:
  arch: amd64
  cgroupManager: cgroupfs
  cgroupVersion: v2
  distribution:
    distribution: fedora
    variant: podman-machine-os
    version: "44"
  kernel: 6.18.54.1-microsoft-standard-WSL2
  networkBackend: netavark
  ociRuntime:
    name: crun
  os: linux
  serviceIsRemote: true
version:
  APIVersion: 6.1.4
  Built: 1791763200
  GitCommit: 464c15fec06f0074c916f9eff87c4806869c2833
  Version: 6.1.4

Podman in a container

No

Privileged Or Rootless

Rootless

Upstream Latest Release

Yes

Additional environment details

Windows 11 / Windows 10 (WSL2 / Hyper-V backend) Podman 6.1.4 release for Windows

Additional information

Workaround: Deleting stale .sock files in %TEMP%\podman\ prior to startup resolves the problem:

Remove-Item "$env:TEMP\podman\*.sock" -Force -ErrorAction SilentlyContinue
podman machine start

Proposed Fix in Go: Before calling net.Listen("unix", path) on Windows:

_ = os.Remove(path)
listener, err := net.Listen("unix", path)

ReluPercan avatar Oct 14 '26 05:10 ReluPercan

Unlike Linux, where Go's net.Listen("unix", path) removes/unlinks dead/stale socket files automatically, on Windows (Winsock AF_UNIX), if the .sock file already exists on the filesystem from a previous run, bind() fails with WSAEADDRINUSE (error code 10048).

That makes no sense to me, on linux/macos a leftover socket file will always fail with address already in use as well. What Go does is to delete the file on Close by default. But of course on a non clean termination that will not happen and then the file is leaked. So of course we need to clean it up ourself on start again.

The only question is should we delete the win-sshproxy socket path on the podman or win-sshproxy side? cc @cfergeau @l0rd

Luap99 avatar Oct 14 '26 08:10 Luap99

There are some code paths in gvisor-tap-vsock where we do not want to remove the socket file before listening, so I’d prefer to never remove socket files. If this is too strict and causes too many problems, we’ll consider removing the socket files which are passed on win-sshproxy/gvproxy command line before Listen, this should be relatively harmless. As you pointed out, regardless of what we do, code will be needed in podman for non-clean termination.

I also need to check if socket files are cleaned up on clean 'win-sshproxy' shutdown, if not this would be a bug we need to fix in win-sshproxy

cfergeau avatar Oct 14 '26 14:10 cfergeau

If this is too strict and causes too many problems, we’ll consider removing the socket files which are passed on win-sshproxy/gvproxy command line before Listen, this should be relatively harmless. As you pointed out, regardless of what we do, code will be needed in podman for non-clean termination.

Yeah I understand your concern but cli arguments should be trusted, but I certainly understand the argument of the process does not know if the existing socket is still in use. Doing the removal on the podman side only would be fine with me.

I also need to check if socket files are cleaned up on clean 'win-sshproxy' shutdown, if not this would be a bug we need to fix in win-sshproxy

The go std libary removes the file as long as you call Close() on the listener before program exit.

Luap99 avatar Oct 14 '26 14:10 Luap99

    > I also need to check if socket files are cleaned up on clean 'win-sshproxy' shutdown, if not this would be a bug we need to fix in win-sshproxy
        
    The go std libary removes the file as long as you call Close() on the listener before program exit.

win-sshproxy apparently does the right thing from that perspective, but since there is this bug report, I prefer to carry out more extensive testing in case I misread the code.

cfergeau avatar Oct 14 '26 15:10 cfergeau

I'm hitting this too, and can add a data point for @cfergeau's question about clean shutdowns.

Environment: Podman 6.1.4 (Windows client), Windows 11, WSL provider, rootful machine, Podman Desktop 1.30.5.

What happened: I rebooted Windows while the machine was running. On the next podman machine start, the CLI printed win-sshproxy.exe failed to start, exit code: 0 (see windows event logs), but still ended with "started successfully". The Event Viewer entry matches this issue exactly:

[error] podman-machine-default: Error occurred in execution group: error listening on socket: .../Temp/podman/podman-machine-default-api.sock: listen unix ...: bind: Only one usage of each socket address (protocol/network address/port) is normally permitted.

The same log shows win-sshproxy listening on both \\.\pipe\podman-machine-default and \\.\pipe\docker_engine right before this error. The process then exits, so both pipes disappear. The CLI keeps working over SSH, but Podman Desktop and Docker API clients lose API forwarding. Podman Desktop showed no containers, images or volumes (connect ENOENT \\.\pipe\podman-machine-default).

Clean shutdown: for me, podman machine stop removes podman-machine-default-api.sock, so the leak only seems to happen on a non-clean exit such as a reboot with the machine running.

Workaround: with the machine stopped, deleting that one stale file makes podman machine start work and Podman Desktop shows my data again.

This worked for me on earlier version 6 without any manual step (I could reboot with the machine running), so a cleanup on start in Podman, as discussed above, would fix it.

andju avatar Oct 15 '26 22:10 andju

Hitting this too, with two extra data points that may matter for the fix.

Environment: Podman 6.1.4 (Windows client), Windows 11 Enterprise 26200, WSL provider, rootful machine, Podman Desktop 1.30.5.

Symptom: Podman Desktop showed no containers while podman ps -a listed all of them. \\.\pipe\podman-machine-default and \\.\pipe\docker_engine did not exist and no win-sshproxy.exe was running. The stale %TEMP%\podman\podman-machine-default-api.sock (0 bytes) dated from the previous day.

1. A clean stop/start does not help, and the bind error changes

The first failure (the first machine start of the day) logged the same error as this issue:

bind: Only one usage of each socket address (protocol/network address/port) is normally permitted.

After a clean podman machine stop / podman machine start, with no win-sshproxy.exe or gvproxy.exe running, it still failed, but with a different error:

[error] podman-machine-default: Error occurred in execution group: error listening on socket: /C:/Users/<user>/AppData/Local/Temp/podman/podman-machine-default-api.sock: listen unix C:/Users/<user>/AppData/Local/Temp/podman/podman-machine-default-api.sock: bind: An invalid argument was supplied.

So anyone searching for WSAEADDRINUSE alone may miss this one. In both cases the CLI prints win-sshproxy.exe failed to start, exit code: 0 and then started successfully.

2. The stale socket file cannot be deleted directly

With the machine stopped, every way I tried to delete the file failed:

Method Result
Remove-Item -Force The file cannot be accessed by the system.
cmd /c del /f /q The file cannot be accessed by the system.
fsutil reparsepoint delete Error 1920: The file cannot be accessed by the system.
[System.IO.File]::Delete() The file cannot be accessed by the system.

What worked was renaming the parent folder (%TEMP%\podman to %TEMP%\podman.stale-<timestamp>) and then running podman machine start. After that, win-sshproxy started, both pipes came back, and Podman Desktop saw the containers again.

If the fix removes the socket file before Listen, it may hit the same error on some systems. A fallback such as renaming the file (or its directory) could be needed, or a log message that tells the user what to remove manually.

Workaround for others:

podman machine stop
Rename-Item "$env:LOCALAPPDATA\Temp\podman" "podman.stale-$(Get-Date -f yyyyMMddHHmmss)"
podman machine start

#29985 looks like the same root cause (WSL, 6.1.4, proxy exits with code 0, no pipe).

SrilalS avatar Oct 16 '26 04:10 SrilalS

~~This is fixed in the main branch https://github.com/podman-container-tools/podman/pull/29765~~ edit: that one and this one are distinct problems

On main branch, on podman machine start, we check if 1) the pipe is in use 2) the file win-sshproxy.tid exists. When both conditions are met, we kill the corresponding process and, after checking that the pipe is no longer in use, start win-sshproxy. I don't think we need to delete the socket.

But there are a few open questions:

  • previously (v6.1.3) this wasn't a big deal on WSL: podman machine start reported the error could not start api proxy, but the pre-existing win-sshproxy was still working and forwarding podman commands. It looks like with v6.1.4 it no longer works.
  • the workaround described in this issue, removing the .sock file, should not fix podman machine start. After removing the UNIX socket, the leftover win-sshproxy will still be listening to the pipe \\\\.\\pipe\\podman-machine-default, and podman machine start should still report the same error

I want to investigate these before closing this issue.

And I found another, more subtle bug related to that: wsl --shutdown (non-clean machine termination), followed by a podman machine rm/reset, deletes win-sshproxy.tid without stopping the process. Then the next podman machine start fails because it can't find the win-sshproxy tid. I am preparing a PR to fix that too.

l0rd avatar Oct 16 '26 11:10 l0rd

I was wrong: the problem exists in main branch too. It can be reproduced easily by 1) killing win-sshproxy Stop-Process -Name "win-sshproxy" and 2) restarting the machine podman machine restart.

It started with gvproxy v0.9.0 and affects Hyper-V too (gvproxy.exe). You can also reproduce it on macOS by sending SIGKILL to gvproxy. But it's less critical on macOS because the host sends SIGTERM on shutdown, and gvproxy can exit cleanly in that case.

On the Podman side, we should check for an existing sock file before starting gvproxy/win-sshproxy and eventually delete it. I am working on a fix.

On gvproxy/win-sshproxy (or rather winquit side), we should handle signals sent when the host is shutting down (WM_QUERYENDSESSION/WM_ENDSESSION).

l0rd avatar Oct 19 '26 14:10 l0rd

@l0rd it looks like in gvisor-tap-vsock v0.9.0 it stopped removing a stale socket before listening. containers/gvisor-tap-vsock@ba6d975 (part of containers/gvisor-tap-vsock#718) dropped the os.Remove(path) in listenUnix:

  • before: https://github.com/containers/gvisor-tap-vsock/blob/v0.8.9/pkg/sshclient/ssh_forwarder.go#L119
  • after: https://github.com/containers/gvisor-tap-vsock/blob/v0.9.0/pkg/sshclient/ssh_forwarder.go#L112-L116

It also isn't reported as an error: win-sshproxy exits 0 after logging it (main.go#L113-L116), and LaunchWinProxy only prints a notice, so machine start still succeeds (machine_windows.go#L104-L110).

PS: I tested a Podman-side fix locally. In cleanupStaleHostForwarder (networking_windows.go#L28-L53), once the stale proxy check passes, delete the API socket:

sock, err := mc.APISocket()
if err != nil {
	return err
}
return sock.Delete() // ignores ErrNotExist

At that point the pipe is free and the machine start lock is held, so no live proxy owns the socket. It runs for both WSL and Hyper-V. Repro: kill the proxy with Stop-Process -Force, then machine stop and machine start.

Provider main (6b5f0e9) with fix
WSL start "succeeds", no pipe pipe up
Hyper-V ssh error: machine is not listening on ssh port starts, pipe up

This doesn't fix the shutdown handling in winquit / gvisor-tap-vsock. The proxy still leaves the file behind when Windows shuts down. But Podman removes it on the next start, so it no longer matters for this bug. Happy to open a PR with this if you haven't started one.

SrilalS avatar Oct 19 '26 15:10 SrilalS

8. Hitting this too, with two extra data points that may matter for the fix. Environment: Podman 6.1.4 (Windows client), Windows 11 Enterprise 26200, WSL provider, rootful machine, Podman Desktop 1.30.5. Symptom: Podman Desktop showed no containers while podman ps -a listed all of them. \\.\pipe\podman-machine-default and \\.\pipe\docker_engine did not exist and no win-sshproxy.exe was running. The stale %TEMP%\podman\podman-machine-default-api.sock (0 bytes) dated from the previous day. ### 1. A clean stop/start does not help, and the bind error changes The first failure (the first machine start of the day) logged the same error as this issue: bind: Only one usage of each socket address (protocol/network address/port) is normally permitted.

After a clean `podman machine stop` / `podman machine start`, with no `win-sshproxy.exe` or `gvproxy.exe` running, it still failed, but with a different error:
```
[error] podman-machine-default: Error occurred in execution group: error listening on socket: /C:/Users/<user>/AppData/Local/Temp/podman/podman-machine-default-api.sock: listen unix C:/Users/<user>/AppData/Local/Temp/podman/podman-machine-default-api.sock: bind: An invalid argument was supplied.
```


    
      
    

      
    

    
  
So anyone searching for `WSAEADDRINUSE` alone may miss this one. In both cases the CLI prints `win-sshproxy.exe failed to start, exit code: 0` and then `started successfully`.
### 2. The stale socket file cannot be deleted directly
With the machine stopped, every way I tried to delete the file failed:



Method
Result




`Remove-Item -Force`
`The file cannot be accessed by the system.`


`cmd /c del /f /q`
`The file cannot be accessed by the system.`


`fsutil reparsepoint delete`
`Error 1920: The file cannot be accessed by the system.`


`[System.IO.File]::Delete()`
`The file cannot be accessed by the system.`



What worked was renaming the parent folder (`%TEMP%\podman` to `%TEMP%\podman.stale-<timestamp>`) and then running `podman machine start`. After that, `win-sshproxy` started, both pipes came back, and Podman Desktop saw the containers again.
If the fix removes the socket file before `Listen`, it may hit the same error on some systems. A fallback such as renaming the file (or its directory) could be needed, or a log message that tells the user what to remove manually.
**Workaround for others:**
podman machine stop
Rename-Item "$env:LOCALAPPDATA\Temp\podman" "podman.stale-$(Get-Date -f yyyyMMddHHmmss)"
podman machine start
    
      
    

      
    

    
  
[#29985](https://github.com/podman-container-tools/podman/issues/29985) looks like the same root cause (WSL, 6.1.4, proxy exits with code 0, no pipe).

@SrilalS Data point on this: it didn't happen on my machine.

  • Podman 6.1.4 (Windows client), WSL machine, rootful
  • Windows 11 Pro 26H2 (OS build 26300.9711)

A 0-byte podman-machine-default-api.sock from a previous run (last written 2026-10-16) was left in %TEMP%\podman, and podman machine start printed win-sshproxy.exe failed to start, exit code: 0 followed by "started successfully".

Remove-Item "$env:TEMP\podman\*.sock" -Force removed the file without any access error (Get-ChildItem -Force listed it with mode -a---l). The next podman machine start reported API forwarding listening on: npipe:////./pipe/docker_engine.

So the "cannot access" error doesn't happen on every setup. I don't know what left the file behind on my machine.

ValkoinenKissa avatar Oct 19 '26 21:10 ValkoinenKissa

I notice that the .sock file at %TEMP%\podman is deleted if I run podman machine stop while Podman is running (i.e., when the machine is stopped by Podman), but not if I restart (tested just now) or shut down (presumably) while Podman is running (i.e., when the machine is stopped externally, by Windows/WSL).

ravindUwU avatar Oct 19 '26 23:10 ravindUwU

@ValkoinenKissa Agreed. file access depends on what terminal and what permissions it runs on and not the cause of the bug. I confirmed the root cause to be the changed behavior in gvisor-tap-vsock in v0.9.0. But fix on podman side is simple enough I was able to build the Podman executable with the fix and been using it since then without this issue coming up.

SrilalS avatar Oct 20 '26 02:10 SrilalS

Had the same problem too. And was quite surprised. After the installation of podman on day 1 it works as expected. The next day I had no idea what it broke it. Today I found that issue and removing the sock file was the solution. Thanks!

ReimarBauer avatar Nov 12 '26 16:11 ReimarBauer

Same issue as @ReimarBauer just today. I assume this is some Windows update issue

MeikelLP avatar Nov 13 '26 09:11 MeikelLP

I can confirm that it is fixed in version v6.2.0

BPJEnnova avatar Nov 13 '26 11:11 BPJEnnova

I'm using RedHat.Podman@5.8.10 via winget. How is it different from Podman.CLI@6.2.0 ?

MeikelLP avatar Nov 13 '26 12:11 MeikelLP

you should update to to 6.2.0, I think you must first uninstall the old installers and then install the new one. The name got switched because this is not a RH specific project as we are part of the CNCF now IIRC

Luap99 avatar Nov 13 '26 12:11 Luap99

Will the fix be backported to podman 5 for those stuck on Windows 10?

Otiel avatar Nov 13 '26 15:11 Otiel

If someone is willing to backport the commit there and fix all the merge conflicts there then we can take it. I was originally assuming this only happens with the new podman/gvproxy combo but since we backported the gvproxy update due some security fixes I suppose we must pick this follow up fix as well then.

Luap99 avatar Nov 13 '26 16:11 Luap99

I will create the backport PR.

l0rd avatar Nov 13 '26 17:11 l0rd