Powerful system container and virtual machine manager https://canonical.com/lxd
  • Go 85%
  • Shell 12.3%
  • C 2.4%
  • Python 0.2%
  • Makefile 0.1%
Find a file
Tom Parrott 19f6761f03
lxd/instance_console: Remove redundant (and unsafe) write (from Incus) (#18477)
Cherry picked from
[2a58e253129851ad1ee8c2ab2822ea7e6714f54a](2a58e25312)

Prevents a daemon panic with concurrent console access; reproduced
consistently on `2a7db370f6`:
```
goroutine 7263 [running]:
github.com/gorilla/websocket.(*messageWriter).flushFrame(0x30e52b0d9ce8, 0x1, {0x30e52a9b8ad8?, 0x30e52b0d9cf0?, 0x4a7585?})
	github.com/gorilla/websocket@v1.5.1/conn.go:632 +0x4a6
github.com/gorilla/websocket.(*Conn).WriteMessage(0x30e52a562c60, 0x0?, {0x30e52a9b8ad8, 0x2, 0x2})
	github.com/gorilla/websocket@v1.5.1/conn.go:785 +0x125
main.(*consoleWs).doConsole.func4()
	github.com/canonical/lxd/lxd/instance_console.go:344 +0x49
main.(*consoleWs).doConsole(0x30e52a4c5490, {0x2974b98, 0x30e52b693260})
	github.com/canonical/lxd/lxd/instance_console.go:365 +0x49d
main.(*consoleWs).Do(0x30e52ac52ef8?, {0x2974b98?, 0x30e52b693260?}, 0x24e27e0?)
	github.com/canonical/lxd/lxd/instance_console.go:226 +0x65
github.com/canonical/lxd/lxd/operations.(*Operation).start.func1({0x2974b98?, 0x30e52b693260?}, 0x30e52a2c2900)
	github.com/canonical/lxd/lxd/operations/operations.go:583 +0x8a
created by github.com/canonical/lxd/lxd/operations.(*Operation).start in goroutine 7192
	github.com/canonical/lxd/lxd/operations/operations.go:536 +0x234
```

using

```sh
#!/bin/bash
set -euo pipefail

vm=nv0

old=$(pgrep -n -x lxd || true)
echo "lxd pid: $old"

rm -f /tmp/console-repro.*

loop() {
    n=$1

    for i in {1..80}; do
        timeout .18 \
            script -qfec "/home/wesley/go/bin/lxc console $vm --type console" \
            "/tmp/console-repro.$n.$i.log" \
            >/tmp/console-repro.$n.out \
            2>>/tmp/console-repro.$n.err || true

        p=$(pgrep -n -x lxd || true)
        if [ "$p" != "$old" ]; then
            echo "lxd restarted: worker=$n iter=$i old=$old new=$p"
            return
        fi
    done
}

for n in {1..6}; do
    loop "$n" &
done

wait
```

The script runs to completion with the fix applied.

## Checklist

- [x] I have read the [contributing
guidelines](https://github.com/canonical/lxd/blob/main/CONTRIBUTING.md)
and attest that all commits in this PR are [signed
off](https://github.com/canonical/lxd/blob/main/CONTRIBUTING.md#including-a-signed-off-by-line-in-your-commits),
[cryptographically
signed](https://github.com/canonical/lxd/blob/main/CONTRIBUTING.md#commit-signature-verification),
and follow this project's [commit
structure](https://github.com/canonical/lxd/blob/main/CONTRIBUTING.md#commit-structure).
- [ ] ~I have checked and added or updated relevant documentation.~
2026-06-17 22:08:05 +01:00
.github github: GHA runners no longer have ephemeral disks 2026-06-17 11:11:55 -04:00
.workshop workshop: add initial definition 2026-06-11 08:18:55 +02:00
client client: Add extension checks to UpdateClusterMemberState 2026-06-15 10:47:33 -07:00
doc doc/references: Update 6.9 release notes with additional changes 2026-06-17 12:06:19 +01:00
fuidshift fuidshift: simplify arg checking to display help 2025-09-06 09:36:30 -04:00
grafana update absolute URL links to LXD docs 2025-05-07 13:37:37 -07:00
lxc Rebalance raft roles during cluster member evacuation (#17911) 2026-06-17 10:05:21 +01:00
lxd lxd/instance_console: Remove redundant (and unsafe) write 2026-06-17 15:13:01 -05:00
lxd-agent lxd-agent/devlxd: guard against client == nil in devLXDMetadataGetHandler() 2026-06-08 16:37:26 -04:00
lxd-benchmark lxd-benchmark: Use consistent error message style 2026-03-13 08:11:52 -07:00
lxd-convert lxd-convert: use %q for file path in error messages 2026-06-10 14:25:17 -04:00
lxd-user Device: Add support for hotplugging GPU CDI devices into containers (#17972) 2026-04-07 10:01:46 +01:00
scripts Makefile: Update check-gomin, update-gomin, and drop update-copilot-instructions 2026-06-08 12:59:57 -07:00
shared Rebalance raft roles during cluster member evacuation (#17911) 2026-06-17 10:05:21 +01:00
test test/suites/basic: simplify check for unconfined Apparmor profile 2026-06-17 09:00:45 -04:00
tools gomod: Update deps 2026-06-16 15:46:41 +01:00
.deepsource.toml Update .deepsource.toml 2023-08-04 10:10:48 +02:00
.gitignore workshop: add initial definition 2026-06-11 08:18:55 +02:00
.golangci.yaml golangci: enable depguard linter 2026-04-11 19:50:41 -04:00
.shellcheckrc shellcheck: enable optional flagging of useless use of cat 2026-01-03 13:22:17 -05:00
.yamllint Makefile: opportunistically run yamllint against GH workflows 2024-10-16 15:15:13 -04:00
AGENTS.md go: Update Go minimum version to 1.26.4 2026-06-09 07:50:15 -04:00
AUTHORS doc: use proper SPDX identifiers for licenses 2024-01-03 10:35:16 -05:00
COMMITS.md github: Add COMMITS.md as single source for commit format 2026-06-08 10:44:21 -07:00
CONTRIBUTING.md github: Add COMMITS.md as single source for commit format 2026-06-08 10:44:21 -07:00
COPYING Change license to AGPLv3 2023-12-12 10:22:48 +00:00
go.mod gomod: Update deps 2026-06-16 15:46:41 +01:00
go.sum gomod: Update deps 2026-06-16 15:46:41 +01:00
Makefile workshop: add initial definition 2026-06-11 08:18:55 +02:00
README.md README: update link to LXD project on Ubuntu Discourse 2026-02-06 14:30:38 -05:00
SECURITY.md SECURITY: Remove monthly from feature release 2024-12-11 08:46:42 +00:00
staticcheck.conf staticcheck.conf: add dedicated config to ignore ST1005 2025-05-14 04:44:33 -04:00

LXD

LXD is a modern, secure and powerful system container and virtual machine manager.

It provides a unified experience for running and managing full Linux systems inside containers or virtual machines. LXD supports images for a large number of Linux distributions (official Ubuntu images and images provided by the community) and is built around a very powerful, yet pretty simple, REST API. LXD scales from one instance on a single machine to a cluster in a full data center rack, making it suitable for running workloads both for development and in production.

LXD allows you to easily set up a system that feels like a small private cloud. You can run any type of workload in an efficient way while keeping your resources optimized.

You should consider using LXD if you want to containerize different environments or run virtual machines, or in general run and manage your infrastructure in a cost-effective way.

Get started

See Getting started in the LXD documentation for installation instructions and first steps.

Status

Type Service Status
Tests GitHub Build Status
Go documentation Godoc GoDoc
Static analysis GoReport Go Report Card

Installing LXD from packages

The LXD daemon only works on Linux but the client tool (lxc) is available on most platforms.

OS Format Command
Linux Snap snap install lxd
Windows Chocolatey choco install lxc
macOS Homebrew brew install lxc

The LXD snap packaging repository is available here.

For more instructions on installing LXD for a wide variety of Linux distributions and operating systems, and to install LXD from source, see How to install LXD in the documentation.

Client SDK packages

The LXD project provides SDK client packages for interacting with LXD servers from your own software.

These SDKs are licensed as Apache-2.0.

Language URL
Go https://pkg.go.dev/github.com/canonical/lxd/client
Python https://github.com/canonical/pylxd

For more information on using the LXD API, see REST API in the documentation.

Tools for managing LXD

If you are looking for tools (beyond lxc CLI) to manage LXD at scale (from single server to wide clusters), the following projects can be useful:

Tool Link
Ansible - connection plugin https://galaxy.ansible.com/ui/repo/published/community/general/content/connection/lxd/
Ansible - inventory plugin https://galaxy.ansible.com/ui/repo/published/community/general/content/inventory/lxd/
Bolt - LXD transport https://www.puppet.com/docs/bolt/latest/bolt_transports_reference.html#lxd
MicroCloud https://canonical.com/microcloud
Packer - LXD builder https://developer.hashicorp.com/packer/integrations/hashicorp/lxd/latest/components/builder/lxd
Terraform provider https://registry.terraform.io/providers/terraform-lxd/lxd

Security

Consider the following aspects to ensure that your LXD installation is secure:

  • Keep your operating system up-to-date and install all available security patches.
  • Use only supported LXD versions (LTS releases or the latest feature release).
  • Restrict access to the LXD daemon and the remote API.
  • Configure your network interfaces to be secure.
  • Do not use privileged containers unless required. If you use privileged containers, put appropriate security measures in place. See Container security for more information.

See Security for detailed information.

IMPORTANT:

Local access to LXD through the Unix socket always grants full access to LXD. This includes the ability to attach file system paths or devices to any instance as well as tweak the security features on any instance.

Therefore, you should only give such access to users who you'd trust with root access to your system.

Community support

You can seek support from the LXD developers as well as the wider community through the following channels.

Forum

Ask questions or engage in discussions: https://discourse.ubuntu.com/c/project/lxd/

Documentation

Access the official documentation: https://documentation.ubuntu.com/lxd/latest/

Bug reports and feature requests

To file a new bug or feature request, submit an issue on GitHub.

Other community resources

You can find additional resources on the LXD website, on YouTube, and the community-created tutorials.

Commercial support

LTS releases of LXD receive standard support for five years, which means they receive continuous updates. Commercial support for LXD is provided as part of Ubuntu Pro (both Infra-only and full Ubuntu Pro), including for attached LXD instances running Ubuntu. See the full service description for details.

Managed solutions and firefighting support are also available for LXD deployments. See: Managed services.

Contributing

Fixes and new features are greatly appreciated. Make sure to read our contributing guidelines first!