WSL2 X11 programs "disappear"
Solution 1:
You're right it's an issue with the networking. It effects all X11 connections to Hyper-V apparently. A solution is to use something other than TCP/IP for the X11 connection.
The developer of the Windows X11 server x410 explained how to fix it for Hyper-V VMs by using Virtual Sockets here.
Unfortunately, he also explains on at the end of this more extensive article he wasn't able to get this working on WSL2. He's going to wait for WSL2 to mature until it has better inter-OS communication via Unix domain sockets.
Solution 2:
You can use Xpra or X2Go as a workaround (for me X2Go works better).
Xpra
- Install Xpra on your Linux distribution (
apt install xpra
on Ubuntu). - Install Xpra on Windows (the installer is under Xpra client Download)
- Launch xpra in Linux using
xpra start --bind-tcp=0.0.0.0:10000 :10000
- Launch
Xpra.exe
in Windows and connect to Port10000
.
The client will reconnect automatically after a sleep/standby. Even when you lose the connection (maybe when logging into a VPN) you can always reconnect manually.
X2Go
- Install X2Go on your Linux distribution (
apt install x2goserver
on Ubuntu). - Install X2Go client on Windows (the installer is under X2Go client Download)
- Fix and start sshd on Linux:
You will also have to start sshd on every WSL restart withsudo apt-get remove --purge openssh-server sudo apt-get install openssh-server sudo service ssh --full-restart
sudo service ssh start
. - Launch the client on Windows, connect using "Session type: Published Applications"
PS: I am currently writing a small blog post: Development Environment in WSL2