I've run into an issue that I don't know how to fix: (lxc can't connect to the socket)

So, when I type lxc list, I get:

Error: Get "http://unix.socket/1.0": dial unix /var/snap/lxd/common/lxd/unix.socket: connect: no such file or directory

So to debug it, I ran lxd --debug --group lxd and the end of the output is:

INFO[02-28|20:18:25]  - closing socket                        socket=[::]:8443
INFO[02-28|20:18:25]  - closing socket                        socket=/var/snap/lxd/common/lxd/unix.socket
INFO[02-28|20:18:25] Stopping /dev/lxd handler:
INFO[02-28|20:18:25]  - closing socket                        socket=/var/snap/lxd/common/lxd/devlxd/sock
DBUG[02-28|20:18:25] Not unmounting temporary filesystems (containers are still running)
Error: failed to open cluster database: failed to ensure schema: failed to apply update 43: Failed adding unique index to storage_pools_config and networks_config tables: UNIQUE constraint failed: index 'networks_unique_network_id_node_id_key'

Any thoughts on how I fix this? Thanks.

Ubuntu focal
snap: latest/stable: 4.11 2021-02-26 (19566) 74MB -

@tomp can you look into this one? I believe you’re the one who added that schema update.

@ajkavanagh if there’s nothing sensitive in there, could you pastebin sqlite3 /var/snap/lxd/common/lxd/database/global/db.bin .dump?

This is likely caused by the same issue as the error others have seen: “Duplicate config row found for key …”

And the original reported issue here:

In your case, you’ve likely just upgraded and jumped several releases such as to miss the interim release that just detected these issues and gave the error seen in those other reports, and instead got caught out by the schema change we added to prevent the issue happening in the future.

Please could you provide the output of:

sudo sqlite3 /var/snap/lxd/common/lxd/database/global/db.bin
sqlite> SELECT * FROM networks;
sqlite> SELECT * FROM networks_config;

Sorry for the delay. Got tied up doing other things, and it’s “only” my laptop that’s broken. The desktop is working fine and that’s where I tend to use lxc (apart from my server, where I use it for lots of things :slight_smile: )

Anyway, here is the dump file: https://paste.ubuntu.com/p/GXSBKT5C9f/

I think it’s entirely possible that I’ve jumped versions (or even broken things by messing around with the snap – I ran out of diskspace and had to uninstall things, then re-install them once I’d managed to move stuff around). So, I suspect this is entirely my fault!

Dumps as requested:

~$ sudo sqlite3 /var/snap/lxd/common/lxd/database/global/db.bin
SQLite version 3.31.1 2020-01-27 19:55:54
Enter ".help" for usage hints.
sqlite> SELECT * FROM networks;
sqlite> SELECT * FROM networks_config;

So the issue is that the ipv4.address field’s setting is specified twice, rows 2 none and 15

Assuming that the latter ID row 15 is the most recently specified and thus the one you actually want to keep, then we need to remove the row ID 2 from the networks_config table.

As LXD won’t start, to do this we use a patch SQL file which LXD runs at start up, to correct the error.

So as per the other threads, you’d need to create a file called /var/snap/lxd/common/lxd/database/patch.global.sql containing:

DELETE FROM networks_config WHERE id = 2;

And then start LXD.

1 Like

Hi Tomas

Thanks for the fix. I have applied it and it has started again. Much appreciated.