moby: docker network rm `networkname` has error has active endpoints

Description when running

$ docker network rm new-mail_develop_default 
error response from daemon: error while removing network: network new-mail_develop_default id 469e10dee4acb100fb868d7709bd83c75beeded79962cc574d47976495668d89 has active endpoints
$ docker network ls
NETWORK ID     NAME                       DRIVER    SCOPE
1183956ec66a   bridge                     bridge    local
1c98ceffa4d4   host                       host      local
469e10dee4ac   new-mail_develop_default   bridge    local
4826ed19a910   none                       null      local
$ docker network inspect new-mail_develop_default
[
    {
        "Name": "new-mail_develop_default",
        "Id": "469e10dee4acb100fb868d7709bd83c75beeded79962cc574d47976495668d89",
        "Created": "2021-03-08T12:28:54.020954486+03:00",
        "Scope": "local",
        "Driver": "bridge",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": null,
            "Config": [
                {
                    "Subnet": "192.168.0.0/20",
                    "Gateway": "192.168.0.1"
                }
            ]
        },
        "Internal": false,
        "Attachable": true,
        "Ingress": false,
        "ConfigFrom": {
            "Network": ""
        },
        "ConfigOnly": false,
        "Containers": {},
        "Options": {},
        "Labels": {
            "com.docker.compose.network": "default",
            "com.docker.compose.project": "new-mail_develop",
            "com.docker.compose.version": "1.27.4"
        }
    }
]
$ docker ps -a
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES

Steps to reproduce the issue:

  1. Cannot be reproduce special case

Describe the results you received: remove network

Describe the results you expected: remove network

Additional information you deem important (e.g. issue happens only occasionally):

Output of docker version:

Docker version 20.10.3, build 48d30b5

Output of docker info:

Client:
 Context:    default
 Debug Mode: false
 Plugins:
  app: Docker App (Docker Inc., v0.9.1-beta3)
  buildx: Build with BuildKit (Docker Inc., v0.5.1-docker)

Server:
 Containers: 0
  Running: 0
  Paused: 0
  Stopped: 0
 Images: 72
 Server Version: 20.10.3
 Storage Driver: overlay2
  Backing Filesystem: xfs
  Supports d_type: true
  Native Overlay Diff: true
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 1
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 269548fa27e0089a8b8278fc4fc781d7f65a939b
 runc version: ff819c7e9184c13b7c2607fe6c30ae19403a7aff
 init version: de40ad0
 Security Options:
  seccomp
   Profile: default
 Kernel Version: 3.10.0-1160.15.2.el7.x86_64
 Operating System: CentOS Linux 7 (Core)
 OSType: linux
 Architecture: x86_64
 CPUs: 8
 Total Memory: 15.51GiB
 Name: up-jenkins01.pusula.net.tr
 ID: TAN6:P6A4:CLRY:GP46:6CLZ:RBUT:YO3V:I2AF:YXRB:26ON:UX3D:ZJYC
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false

Additional environment details (AWS, VirtualBox, physical, etc.): proxmox

About this issue

  • Original URL
  • State: open
  • Created 6 years ago
  • Reactions: 26
  • Comments: 32 (4 by maintainers)

Commits related to this issue

Most upvoted comments

We have the same issue on a non proxmox environment

Client:
 Context:    default
 Debug Mode: false
 Plugins:
  app: Docker App (Docker Inc., v0.9.1-beta3)
  buildx: Build with BuildKit (Docker Inc., v0.5.1-docker)

Server:
 Containers: 0
  Running: 0
  Paused: 0
  Stopped: 0
 Images: 24
 Server Version: 20.10.4
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Native Overlay Diff: true
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 1
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 269548fa27e0089a8b8278fc4fc781d7f65a939b
 runc version: ff819c7e9184c13b7c2607fe6c30ae19403a7aff
 init version: de40ad0
 Security Options:
  apparmor
  seccomp
   Profile: default
 Kernel Version: 4.19.0-14-amd64
 Operating System: Debian GNU/Linux 10 (buster)
 OSType: linux
 Architecture: x86_64
 CPUs: 3
 Total Memory: 9.528GiB
 Name: <censore>
 ID: ES76:Q3LQ:A2MI:AHZ3:K7RS:WELI:7OYF:7SWB:CNLB:6ZDF:ONZ5:NCGR
 Docker Root Dir: /mnt/data/docker/data
 Debug Mode: false
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false

WARNING: No swap limit support

while no container is attached

docker inspect testing_default
[
    {
        "Name": "testing_default",
        "Id": "ba43b3a8d952d30bceb36d9f76e110958065cb605c033e4282696e5df7e2ca4f",
        "Created": "2021-03-23T20:09:26.959545689+01:00",
        "Scope": "local",
        "Driver": "bridge",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": null,
            "Config": [
                {
                    "Subnet": "10.249.249.128/25"
                }
            ]
        },
        "Internal": false,
        "Attachable": true,
        "Ingress": false,
        "ConfigFrom": {
            "Network": ""
        },
        "ConfigOnly": false,
        "Containers": {},
        "Options": {
            "com.docker.network.bridge.name": "dw1"
        },
        "Labels": {
            "com.docker.compose.network": "default",
            "com.docker.compose.project": "testing",
            "com.docker.compose.version": "1.28.4"
        }
    }
]

and not even a single container exists

docker ps -a
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES

Seems to be happening with the new docker engine, 18.xx seems to work just fine. Fairly blocking since it reoccurs frequently.

There is no way to fix this issue besides restarting the docker-engine itself. We neither can do either of this

  • docker network prune --force
  • docker network rm testing_default
  • readd some random container to the network, remove the container and try to remove the network then

@sonersivri you should probably rename the issue to include ‘while no containers exist’ because there are a couple of other issues with ‘still active endpoints’ which actually have attached containes - which we do not have here and that should be an important difference

@EugenMayer There are cases where the issue is related to what users do, for instance when there’s an orphaned Compose container left over, or a container manually connected to a Compose network. In those cases, the improved error message will help users determine what’s going on.

I recognize this is probably not the most prominent cause.

i’am not sure it is argueable at all, that this is a bug. This is a bug.

It’s more than probable that there’s a low-level bug lying around somewhere… This is what I wrote in #49736:

Libnetwork is afflicted by long-standing data consistency issues caused by its persistence layer creating new instances of Network, Endpoint and Sandbox every time an object is loaded from the datastore or its in-memory cache.

Fixing the data persistence layer itself is particularly hard as it touches virtually all code paths in libnetwork. We need to be especially cautious with mutex locking – libnetwork makes heavy use of mutexes, but since two concurrent API calls referencing the same object result in to two different instances of that object living in memory, the concurrency model might be broken (unknowingly).

Some of the design decisions that led to this are related to the the eventually-consistent nature of remote datastores used by Classic Swarm.

Classic Swarm went out-of-support 5 years ago, and yet we’re still repaying some of its tech debt. It’s a pitty, I know.

With #49736, we’re bypassing the afflicted code-path, so hopefully the user-facing bug (i.e. “has active endpoints” when it’s not) will be fixed. I can’t be sure, because I don’t have any simple repro that be can transformed into a regression test…

The findings in this comment are interesting: https://github.com/moby/moby/issues/42119#issuecomment-1398975494. It matches the hypothesis I made in #49736 – i.e. the EndpointCnt struct goes out of sync with the on-disk Endpoint. But it also talks about on-disk Endpoint that actually do not exist… So I can’t tell for sure.

Fortunately this PR is also putting us on the right track to gradually fix the concurrency model by letting more code-paths bypass the faulty data-persistence layer.

Just hit an even worse repro of this issue. This time, restarting docker (or the entire system) did not resolve the issue. The rogue docker network was not visible in the output of docker network ls. However, the br-... interface still showed up in the output of ifconfig. docker network inspect <...> on that network returned nothing. Tried force deleting the interface with ip link delete br-.... Upon reboot, the interface was recreated. Still didn’t show up in the output of docker network ls.

The solution we found was to delete the file /var/lib/docker/network/files/local-kv.db and reboot. Thanks to @jest for pointing me in the right direction with your analysis.

Really hope someone at docker can look at this issue, it’s a rather serious bug.

Docker Version
Client: Docker Engine - Community
 Version:           27.3.1
 API version:       1.47
 Go version:        go1.22.7
 Git commit:        ce12230
 Built:             Fri Sep 20 11:41:00 2024
 OS/Arch:           linux/amd64
 Context:           default

Server: Docker Engine - Community
 Engine:
  Version:          27.3.1
  API version:      1.47 (minimum version 1.24)
  Go version:       go1.22.7
  Git commit:       41ca978
  Built:            Fri Sep 20 11:41:00 2024
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.7.22
  GitCommit:        7f7fdf5fed64eb6a7caf99b3e12efcf9d60e311c
 nvidia:
  Version:          1.1.14
  GitCommit:        v1.1.14-0-g2c9f560
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

docker --version Docker version 20.10.7, build f0df350

on Ubuntu 18.04.5

docker network rm netA
Error response from daemon: error while removing network: network netA id 881a8b7416c1d0f432699c4bbd0ae5da68cd53b8df08229ef9d2a57568cb1b9d has active endpoints

docker container ls --all
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES

sudo systemctl restart docker 

docker network rm netA

Restating the daemon works

@akerouanton i’am not sure it is argueable at all, that this is a bug. This is a bug.

#49736 / #49773 might finally fix the bug with the “active endpoints” that do actually not exists, that plague so many people and even forced us to restart the docker engine every time we shutdown the application stack (before we upgrade). Happily, we have a single stack per docker engine … this is not possible for all the people out there. This bug exists since years and is as important as “you cannot upgrade via dc pull && dc up” without hands on any longer. The bug i’am talking about is #23302 … has been closed without ever being fixed.

Just happened to me as well. I solved it by restarting docker service, I can do that right now since this is a new server setup but wont be able to in the future once we have services running.

For the record, I’ve made two changes in this area in the past week:

  1. https://github.com/moby/moby/pull/49736 – only use in-memory values to determine if the network has active endpoints.
  2. https://github.com/moby/moby/pull/49773 – slightly changed the error message to include the name of active endpoints.

Hopefully the 2nd change will help users figure if the error is legit (e.g. an orphaned Compose container is still running), or if this is caused by a bug.

These changes will be available in the next release (v28.1). We’ll build an RC1 tomorrow, so it should be available soon.

@EugenMayer that might be a trace… I just realized that the error occurs on my two server machines, where the backing filesystem for /var/lib/docker is XFS…

I don’t know about the popularity of such a choice, but quite a few of the reports in the above comments also mention XFS.

This might be the issue with bbolt itself, where some of the assumptions it has e.g. about low-level filesystem behavior does not hold for either BTRFS or XFS.

We are also seeing this issue on Rocky Linux 8

docker version
Client: Docker Engine - Community
 Version:           26.0.0
 API version:       1.45
 Go version:        go1.21.8
 Git commit:        2ae903e
 Built:             Wed Mar 20 15:19:04 2024
 OS/Arch:           linux/amd64
 Context:           default

Server: Docker Engine - Community
 Engine:
  Version:          26.0.0
  API version:      1.45 (minimum version 1.24)
  Go version:       go1.21.8
  Git commit:       8b79278
  Built:            Wed Mar 20 15:17:57 2024
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.28
  GitCommit:        ae07eda36dd25f8a1b98dfbf587313b99c0190bb
 runc:
  Version:          1.1.12
  GitCommit:        v1.1.12-0-g51d5e94
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

After restarting the docker daemon, I am able to remove the network. Running docker system prune --force doesn’t help for me.

@jest: Thanks for the detailed look into it. I also had the hunch, that is was tracking the number of containers in the network via some variable which it fails to decrement to zero and then it refuses to remove the container because it only checks that value at that point.

I also think there are concurrent database accesses which mess up that value resulting in an inconsistency.

You are also correct that this issue exists for quite some time already. You can find people all over the internet running into it and the only “solution” is to restart dockerd…

Maybe with your detailed information someone is willing to dig into it and find the offending database interactions.

Some other workaround that I have found:

docker compose down --remove-orphans --timeout 30 # this might fail with the removal error
docker system prune --force # this seems to get rid of the broken network
docker compose down --remove-orphans --timeout 30 # this does not fail anymore

We are doing this for 6 weeks now and haven’t hit the bug again. We might be lucky, or this is another workaround without shutting down dockerd.

We’re seeing this same issue as well with docker 20.10.5. We have a CI/CD that is spawning hundreds of dockers and with docker 19.03 we never had issues with “docker-compose down” reporting active endpoints. We recently upgraded to docker 20.10.5 and we’re hitting this problem tens of times per day on that CI/CD pipeline.

Let me know if there’s any log I can collect to help debugging this issue.