lima-vm / lima-vm/lima

Lima's X11 forwarding breaks after a MacBook goes to sleep

Open
#2,099 13 comments 2 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
21.9k
Forks
957
Avg merge
2d 6h
Merged PRs (30d)
53

Description

## Summary

I'm trying to get Lima to work with XQuartz to run graphical applications. It mostly just works, except when my MacBook goes to sleep and wakes up again. After that, applications inside Lima can no longer seem to connect to X11 with messages like:

```
xterm: Xt error: Can't open display: localhost:12.0
```

Cc: #151, #877
## My setup
I'm using Sonoma 14.2.1 on an M2 Apple silicon MacBook Pro. I installed XQuartz from its website, it reports `XQuartz 2.8.5 (xorg-server 21.1.6)`. I'm running a Debian container. I added the following lines to `limactl edit` config file:

```yaml
ssh:
forwardX11: true
forwardAgent: true
```

I also ran `sudo apt install xterm` in the container.

Here is some more sysinfo:

```
# On host system
$ uname -a
Darwin macaw.local 23.2.0 Darwin Kernel Version 23.2.0: Wed Nov 15 21:55:06 PST 2023; root:xnu-10002.61.3~2/RELEASE_ARM64_T6020 arm64 arm Darwin
$ limactl shell debian uname -a
Linux lima-debian 6.1.0-16-cloud-arm64 #1 SMP Debian 6.1.67-1 (2023-12-12) aarch64 GNU/Linux
$ lima --version
limactl version 0.19.0
```

This is a QEMU VM.

VM config (`lima.yaml`)

```yaml
# This template requires Lima v0.7.0 or later
images:
# Try to use release-yyyyMMdd image if available. Note that release-yyyyMMdd will be removed after several months.
- location: "https://cloud.debian.org/images/cloud/bookworm/20231013-1532/debian-12-genericcloud-amd64-20231013-1532.qcow2"
arch: "x86_64"
digest: "sha512:6b55e88b027c14da1b55c85a25a9f7069d4560a8fdb2d948c986a585db469728a06d2c528303e34bb62d8b2984def38fd9ddfc00965846ff6e05b01d6e883bfe"
- location: "https://cloud.debian.org/images/cloud/bookworm/20231013-1532/debian-12-genericcloud-arm64-20231013-1532.qcow2"
arch: "aarch64"
digest: "sha512:b3754e8c4b474fad2f0bb6d483158cc8e6661cf481dcd7a8c55cc128acb4cd2d829d4afe024462ae45028f33ab977d69737d820c8f6c56800cc133cdcfb5874d"
# Fallback to the latest release image.
# Hint: run `limactl prune` to invalidate the cache
- location: "https://cloud.debian.org/images/cloud/bookworm/latest/debian-12-genericcloud-amd64.qcow2"
arch: "x86_64"
- location: "https://cloud.debian.org/images/cloud/bookworm/latest/debian-12-genericcloud-arm64.qcow2"
arch: "aarch64"
mounts:
- location: "~"
- location: "/tmp/lima"
writable: true
ssh:
forwardX11: true
forwardAgent: true
```

However, I also checked that this affects a VZ VM based on the "default" template in exactly the same way.

## The problem
If I have XQuartz running, `limactl shell debian xterm` works fine at first. However, if I close the lid of the computer and reopen it an hour later, it no longer works. The error message is what I quoted before: `xterm: Xt error: Can't open display: localhost:12.0`.

Interestingly, the `xterm` I ran before closing the lid still runs and responds to new input after the lid is reopened. However, I cannot start new graphical applications from it either.

## Workaround

Restarting the VM fixes the problem. I haven't yet found a better workaround, please let me know if you know one!

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.