Commit a1f0b01
authored
fix: race condition in PodUpdateOrAddIfNotExist reading pool without lock (#2578)
* fix: race condition in PodUpdateOrAddIfNotExist reading pool without lock
`PodUpdateOrAddIfNotExist()` accessed `ds.pool` (nil check, `TargetPorts`
iteration) at some call sites without acquiring `ds.mu.RLock()`. Meanwhile,
`PoolSet()` replaces `ds.pool` under `ds.mu.Lock()`. Under concurrent
pod reconciliation and pool updates, this causes:
1. **Nil pointer panic**: `PoolSet(ctx, reader, nil)` sets `ds.pool = nil`
between the nil check and `ds.pool.TargetPorts` access.
2. **Inconsistent reads**: the first half of the function reads old pool's
`TargetPorts` while the second half reads the new pool's, leading to
orphaned or missing endpoints.
**Fix**: snapshot `ds.pool` under `RLock` at function entry and use the
local copy throughout.
* update comments based on ahg-g's comments1 parent 65503c1 commit a1f0b01
2 files changed
Lines changed: 85 additions & 12 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
272 | 272 | | |
273 | 273 | | |
274 | 274 | | |
275 | | - | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
276 | 290 | | |
277 | 291 | | |
278 | 292 | | |
| |||
282 | 296 | | |
283 | 297 | | |
284 | 298 | | |
285 | | - | |
| 299 | + | |
286 | 300 | | |
287 | 301 | | |
288 | 302 | | |
289 | | - | |
290 | | - | |
| 303 | + | |
| 304 | + | |
291 | 305 | | |
292 | 306 | | |
293 | 307 | | |
| |||
324 | 338 | | |
325 | 339 | | |
326 | 340 | | |
327 | | - | |
| 341 | + | |
328 | 342 | | |
329 | 343 | | |
330 | 344 | | |
| |||
372 | 386 | | |
373 | 387 | | |
374 | 388 | | |
375 | | - | |
| 389 | + | |
376 | 390 | | |
377 | 391 | | |
378 | 392 | | |
| |||
395 | 409 | | |
396 | 410 | | |
397 | 411 | | |
398 | | - | |
399 | | - | |
| 412 | + | |
| 413 | + | |
400 | 414 | | |
401 | 415 | | |
402 | 416 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| 25 | + | |
25 | 26 | | |
26 | 27 | | |
27 | 28 | | |
| |||
1095 | 1096 | | |
1096 | 1097 | | |
1097 | 1098 | | |
| 1099 | + | |
| 1100 | + | |
| 1101 | + | |
| 1102 | + | |
| 1103 | + | |
| 1104 | + | |
| 1105 | + | |
| 1106 | + | |
| 1107 | + | |
| 1108 | + | |
| 1109 | + | |
| 1110 | + | |
| 1111 | + | |
| 1112 | + | |
| 1113 | + | |
| 1114 | + | |
| 1115 | + | |
| 1116 | + | |
| 1117 | + | |
| 1118 | + | |
| 1119 | + | |
| 1120 | + | |
| 1121 | + | |
| 1122 | + | |
| 1123 | + | |
| 1124 | + | |
| 1125 | + | |
| 1126 | + | |
| 1127 | + | |
| 1128 | + | |
| 1129 | + | |
| 1130 | + | |
| 1131 | + | |
| 1132 | + | |
| 1133 | + | |
| 1134 | + | |
| 1135 | + | |
| 1136 | + | |
| 1137 | + | |
| 1138 | + | |
| 1139 | + | |
| 1140 | + | |
| 1141 | + | |
| 1142 | + | |
| 1143 | + | |
| 1144 | + | |
| 1145 | + | |
| 1146 | + | |
| 1147 | + | |
| 1148 | + | |
| 1149 | + | |
| 1150 | + | |
| 1151 | + | |
| 1152 | + | |
| 1153 | + | |
| 1154 | + | |
| 1155 | + | |
| 1156 | + | |
| 1157 | + | |
| 1158 | + | |
| 1159 | + | |
1098 | 1160 | | |
1099 | 1161 | | |
1100 | 1162 | | |
| |||
1214 | 1276 | | |
1215 | 1277 | | |
1216 | 1278 | | |
1217 | | - | |
1218 | | - | |
1219 | | - | |
1220 | | - | |
| 1279 | + | |
1221 | 1280 | | |
1222 | 1281 | | |
1223 | 1282 | | |
| |||
0 commit comments