Commit d60c71a
committed
libnetwork/d/overlay: fix logical race conditions
The concurrency control in the overlay driver is logically unsound.
While the use of mutexes is sufficient to prevent data races --
violations of the Go memory model -- many operations which need to be
atomic are performed with unbounded concurrency.
Overhaul the use of locks in the overlay network driver. Implement sound
locking at the network granularity: operations may proceed concurrently
iff they are being applied to distinct networks. Push the responsibility
of locking up to the code which calls methods or accesses struct fields
to avoid deadlock situations like we had previously with
d.initSandboxPeerDB() and to make the code easier to reason about.
Each overlay network has a distinct peer db. The NetworkDB watch for the
overlay peer table for the network will only start after
(*driver).CreateNetwork returns and will be stopped before libnetwork
calls (*driver).DeleteNetwork, therefore the lifetime of the peer db for
a network is constrained to the lifetime of the network itself. Yet the
peer db for a network is tracked in a dedicated map, separately from the
network objects themselves. This has resulted in a parallel set of
mutexes to manage concurrency of the peer db distinct from the mutexes
for the driver and networks. Move the peer db for a network into a field
of the network struct and guard it from concurrent access using the
per-network lock. Move the methods for manipulating the peer db into the
network struct so that the methods can only be called if the caller has
a reference to the network object.
Network creation and deletion are synchronized using the driver-scope
mutex, but some of the kernel programming is performed outside of the
critical section. It is possible for network deletion to race with
recreating the network, interleaving the kernel programming for the
network creation and deletion, resulting in inconsistent kernel state.
Parallelize network creation and deletion soundly. Use a double-checked
locking scheme to soundly handle the case of concurrent CreateNetwork
and DeleteNetwork for the same network id without blocking operations
on other networks. Synchronize operations on a network so that
operations on the network such as adding a neighbor to the peer db are
performed atomically, not interleaved with deleting the network.
Signed-off-by: Cory Snider <[email protected]>
(cherry picked from commit 89d3419)
Signed-off-by: Cory Snider <[email protected]>1 parent ad54b8f commit d60c71a
5 files changed
Lines changed: 221 additions & 272 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
28 | | - | |
29 | | - | |
30 | | - | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
31 | 31 | | |
| 32 | + | |
32 | 33 | | |
33 | | - | |
| 34 | + | |
34 | 35 | | |
35 | 36 | | |
36 | 37 | | |
| |||
59 | 60 | | |
60 | 61 | | |
61 | 62 | | |
62 | | - | |
63 | | - | |
64 | 63 | | |
65 | 64 | | |
66 | 65 | | |
| |||
82 | 81 | | |
83 | 82 | | |
84 | 83 | | |
85 | | - | |
| 84 | + | |
86 | 85 | | |
87 | 86 | | |
88 | 87 | | |
| |||
115 | 114 | | |
116 | 115 | | |
117 | 116 | | |
118 | | - | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
119 | 120 | | |
120 | 121 | | |
121 | 122 | | |
| |||
188 | 189 | | |
189 | 190 | | |
190 | 191 | | |
191 | | - | |
192 | | - | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
193 | 198 | | |
194 | 199 | | |
| 200 | + | |
195 | 201 | | |
196 | | - | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
197 | 218 | | |
198 | 219 | | |
199 | 220 | | |
| |||
202 | 223 | | |
203 | 224 | | |
204 | 225 | | |
205 | | - | |
206 | | - | |
207 | | - | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
208 | 229 | | |
| 230 | + | |
209 | 231 | | |
210 | | - | |
| 232 | + | |
211 | 233 | | |
212 | 234 | | |
213 | 235 | | |
214 | 236 | | |
215 | 237 | | |
216 | | - | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
217 | 241 | | |
218 | 242 | | |
219 | 243 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | 28 | | |
48 | 29 | | |
49 | 30 | | |
| |||
57 | 38 | | |
58 | 39 | | |
59 | 40 | | |
60 | | - | |
61 | | - | |
62 | | - | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
63 | 44 | | |
| 45 | + | |
64 | 46 | | |
65 | 47 | | |
66 | 48 | | |
| |||
84 | 66 | | |
85 | 67 | | |
86 | 68 | | |
87 | | - | |
| 69 | + | |
88 | 70 | | |
89 | 71 | | |
90 | 72 | | |
| |||
96 | 78 | | |
97 | 79 | | |
98 | 80 | | |
99 | | - | |
100 | | - | |
101 | | - | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
102 | 84 | | |
| 85 | + | |
103 | 86 | | |
104 | | - | |
| 87 | + | |
105 | 88 | | |
106 | 89 | | |
107 | 90 | | |
108 | 91 | | |
109 | | - | |
| 92 | + | |
110 | 93 | | |
111 | 94 | | |
112 | 95 | | |
| |||
0 commit comments