Commit 925e996
committed
Fix foreground stdio deadlock when the internal logging process stops consuming
`nerdctl run` in the foreground tees container stdout/stderr through a
64 KiB pipe to a forked logging process (`nerdctl _NERDCTL_INTERNAL_LOGGING`)
on the same goroutine that drains the container's stdio FIFOs. If that
logging process ever stopped consuming (killed, crashed, OOM), the tee
write blocked forever: nerdctl kept its own copies of the logger pipe read
ends open, so the kernel never delivered EPIPE. The blocked goroutine
stopped draining the stdout FIFO, the container's writer blocked behind the
full pipe at exactly pipe-capacity-plus-one-chunk bytes, the container
never exited, `nerdctl run` never returned, and `nerdctl rm -f` on the
wedged container hung as well.
Four changes, from the analysis in #5137:
- Close the parent's copies of the logger pipe read ends once the logging
process has started (the equivalent of containerd's
binaryIO.CloseAfterStart), so that logger death turns into EPIPE on the
tee instead of an eternal pipe-buffer block.
- Make the logger leg of the stdio tee best-effort: on the first failed
write, warn and stop writing to the logger, but keep streaming to the
attached stdout/stderr. Closing the read ends alone is not enough: the
EPIPE would error the io.MultiWriter, abort the io.CopyBuffer that
drains the container's stdio FIFO, and the container would still wedge
on the undrained FIFO chain behind it. With both changes the attach and
the container survive logger death; the log file is what goes
incomplete (with a warning on nerdctl's stderr).
- In the logging process, do not treat an errored delivery on the task
wait channel as a container exit. containerd's client sends Wait RPC
failures through the same channel as a synthetic ExitStatus; cancelling
the stdio readers on such a delivery silently stopped all logging while
the container was still running - and, before the changes above, wedged
the foreground attach permanently. Re-arm the wait instead, and close
each containerd client once its wait delivers so re-arming does not
accumulate open clients.
- Fail IO setup when a binary-v2 logging binary exits before signalling
readiness (mirroring containerd's n == 0 check); plain binary:// keeps
EOF-as-ready for backward compatibility with third-party logging
binaries.
Fixes #5137
Signed-off-by: An Lu <an.lu.91@googlemail.com>1 parent 98a8ade commit 925e996
4 files changed
Lines changed: 326 additions & 17 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
| 35 | + | |
35 | 36 | | |
36 | 37 | | |
37 | 38 | | |
| |||
52 | 53 | | |
53 | 54 | | |
54 | 55 | | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
55 | 94 | | |
56 | 95 | | |
57 | 96 | | |
| |||
156 | 195 | | |
157 | 196 | | |
158 | 197 | | |
159 | | - | |
| 198 | + | |
| 199 | + | |
160 | 200 | | |
161 | 201 | | |
162 | 202 | | |
163 | 203 | | |
164 | 204 | | |
165 | | - | |
| 205 | + | |
| 206 | + | |
166 | 207 | | |
167 | 208 | | |
168 | 209 | | |
169 | 210 | | |
170 | 211 | | |
171 | | - | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
172 | 215 | | |
173 | 216 | | |
174 | 217 | | |
| |||
184 | 227 | | |
185 | 228 | | |
186 | 229 | | |
187 | | - | |
| 230 | + | |
188 | 231 | | |
189 | 232 | | |
190 | 233 | | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
191 | 251 | | |
| 252 | + | |
| 253 | + | |
192 | 254 | | |
193 | | - | |
| 255 | + | |
| 256 | + | |
194 | 257 | | |
195 | 258 | | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
196 | 265 | | |
197 | | - | |
198 | | - | |
| 266 | + | |
| 267 | + | |
199 | 268 | | |
200 | 269 | | |
201 | 270 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
200 | 200 | | |
201 | 201 | | |
202 | 202 | | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
203 | 217 | | |
204 | 218 | | |
| 219 | + | |
205 | 220 | | |
206 | 221 | | |
207 | 222 | | |
208 | 223 | | |
209 | 224 | | |
210 | | - | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
211 | 231 | | |
212 | 232 | | |
| 233 | + | |
213 | 234 | | |
214 | 235 | | |
215 | 236 | | |
| |||
232 | 253 | | |
233 | 254 | | |
234 | 255 | | |
| 256 | + | |
235 | 257 | | |
236 | 258 | | |
237 | 259 | | |
238 | 260 | | |
239 | | - | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
240 | 267 | | |
241 | 268 | | |
| 269 | + | |
242 | 270 | | |
243 | 271 | | |
244 | 272 | | |
| 273 | + | |
245 | 274 | | |
246 | 275 | | |
247 | 276 | | |
| |||
250 | 279 | | |
251 | 280 | | |
252 | 281 | | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
253 | 286 | | |
254 | 287 | | |
255 | 288 | | |
| |||
374 | 407 | | |
375 | 408 | | |
376 | 409 | | |
377 | | - | |
378 | | - | |
379 | | - | |
380 | | - | |
381 | | - | |
382 | | - | |
383 | | - | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
384 | 437 | | |
385 | | - | |
386 | 438 | | |
387 | 439 | | |
388 | 440 | | |
| |||
0 commit comments