moby: NetworkDB does not always reliably converge
Description
In our setups, we keep having issues around Docker DNS resolution around times where we either:
- restart Docker nodes in quick succession
- update Docker nodes (and therefore restart them in quick succession)
- have network issues
For a second we thought that the MTU settings for the networking controlplane might be the issue, but the issue seems to have happened even on an MTU that fits our setup (we used 1350 instead of the default 1500).
It seems that during these times, the gossip network of networkdb does not get synched up properly. We debugged this with the built in debugging tooling of libnetwork (which is really helpful btw) and found that there exists no mechanism in dockerd that concerns itself with resynching the endpoint_table of networkdb (or overlay_peer_table for that matter but that does not seem to be that much of a problem). We double checked this by going through the code of libnetwork/agent.go:
The only places that update anything in networkdb are calls to addServiceInfoToCluster (CreateEntry), addDriverInfoToCluster (CreateEntry), deleteDriverInfoFromCluster (DeleteEntry), deleteServiceInfoFromCluster (DeleteEntry). disableServiceInNetworkDB (UpdateEntry).
While we might have missed things, here comes our proposal: There should be a (opt-in) docker daemon config option that enables a background job in the docker daemon that on a schedule resyncs all the DNS entries to networkdb. Design wise I have not thought about it a lot, but I imagine that this should be fine to run on a schedule of maybe 1-5 minutes in most clusters. This way, whenever a DNS entry is out of sync things should fix themselves in a somewhat acceptable schedule.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 5
- Comments: 56 (35 by maintainers)
@corhere It’s awesome to see that these network issues are being tackled by you! I think I grew quite a few grey hair because of them 😉
Anyway, I just wanted to note that some of the networking issues I had and that I analyzed above did not self-heal. Not after 30 minutes and not after hours or even days.
@corhere Please check: https://github.com/dhilgarth/swarm-overlay-network-breaker
@arhue I’m in the final stages of an implementation that completely replaces swarms overlay network and internal DNS server. I don’t know if it’s the right place to talk about it but look at my companies GitHub and it should be obvious
@corhere if it helps, I actually was able to create a stable reproduction of some of these issues. I’ll put them in a repo in the coming days and link it here.
Thanks for looking into it. For what it’s worth, I can somewhat confirm this feeling from me reading into the code for about 2-3 hours.
Happy to help here if it’s needed in any way.
Not quite; simply having a container flapping, if it’s the only one on the node attached to the network, is sufficient to trigger the bug. It’s the sequence of events of leaving a network, rejoining, and creating an entry that is the problem. If some other node receives the events in the order CREATE, LeaveNetwork, JoinNetwork, it will mark the entry as deleted and ignore any other copies of the CREATE event (e.g. through bulk syncs) which say otherwise. Once in that state, the node will only converge after one of two things happen. The owning node could update the entry, superseding the bugged marked-as-deleted entry. Or the marked-as-deleted entry gets garbage collected after 30 minutes, allowing the node to accept the non-deleted entry from the next bulk sync. There have been reports that the cluster does self-heal after around 30 minutes; this is why.
Aha, so our working theory is that we could get all of this stable by making endpoint_table a “system table”. So this would mean the changes would also be much more localized than what I proposed.
I think there’s merit to the “system tables” idea I sketched out in https://github.com/moby/moby/issues/47728#issuecomment-2073364693. NetworkDB has already solved the challenges you mention for keeping the table entries themselves within a keyspace up to date. And NetworkDB has a reliable list of all nodes participating in the cluster thanks to the memberlist module. If we had tables where all records are implicitly part of a system keyspace which all nodes in the cluster participate in, the same reliable gossip logic could be used for NetworkDB bookkeeping as is used to synchronize user tables. With such infrastructure in place, NetworkDB could simply use a system table to distribute the node-network mappings reliably to the whole cluster.
There is documentation how this part of moby works here:
https://github.com/moby/moby/blob/master/libnetwork/docs/networkdb.md
Documentation for the debugging tools are here:
https://github.com/moby/moby/blob/f3f20c3a862ff90c7e7b0ee07dabe2176ed0a170/libnetwork/cmd/diagnostic/README.md
NetworkDB not converging in a reasonable amount of time is a bug. It does look like
bulkSyncis intended to be that resynching mechanism you suggest, though apparently it is not working properly. To a first approximation, NetworkDB is a distributed KV store with multiple “keyspaces” (called networks) where each node in the cluster gets to pick and choose which keyspaces to participate in. A node only holds the state for the keyspaces it participates in, and therefore can only receive state updates from other nodes also participating. ~I suspect (from a cursory reading of a small slice of the networkdb package source) that there is a design flaw in how this is implemented: the mapping of nodes to networks is only updated with broadcasts, with no mechanism for recovering from a missed broadcast. That mapping probably has to be reliably distributed—like the KV pairs themselves are—to all nodes in the cluster for bulk sync to reliably converge in imperfect conditions.~HI @s4ke - thank you for the debugging, description and proposal. As I’ve not looked at Swarm in any detail yet, I think @corhere is much better placed to take a look at this.