23

I'm mostly very happy with WSL2 on Windows 10, having just switched from Mac. I run X410 on the Windows host and start X11 apps inside WSL by setting

export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '{ print $2 }'):0.0

before starting my program.

It works fine for a while, but after my computer wakes up from sleep, the X window is gone. The application is still shown as running in ps.

I have a feeling it has to do with losing network connection between the X11 app and the X410 server, but I'm not sure. Has anyone experienced this and come up with a workaround?

I'm on Windows 10 Insider Preview build 18945.

andreas
  • 526

3 Answers3

15

You can use Xpra or X2Go as a workaround (for me X2Go works better).

Xpra

  1. Install Xpra on your Linux distribution (apt install xpra on Ubuntu).
  2. Install Xpra on Windows (the installer is under Xpra client Download)
  3. Launch xpra in Linux using xpra start --bind-tcp=0.0.0.0:10000 :10000
  4. Launch Xpra.exe in Windows and connect to Port 10000.

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

  1. Install X2Go on your Linux distribution (apt install x2goserver on Ubuntu).
  2. Install X2Go client on Windows (the installer is under X2Go client Download)
  3. Fix and start sshd on Linux:
    sudo apt-get remove --purge openssh-server
    sudo apt-get install openssh-server
    sudo service ssh --full-restart
    

    You will also have to start sshd on every WSL restart with sudo service ssh start.

  4. Launch the client on Windows, connect using "Session type: Published Applications"

PS: I am currently writing a small blog post: Development Environment in WSL2

derkoe
  • 251
14

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.

stealthwang
  • 264
  • 3
  • 4
1

There is a perfectly good solution to this: https://github.com/nbdd0121/wsld.

WSL Daemon - Stable X11 connection and time synchronisation for WSL2

It does exactly what one of the other solutions elude to: uses Unix domain sockets. I've been using it for many months without a problem.