Fix fd leak of shim log#3266
Conversation
Codecov Report
@@ Coverage Diff @@
## master #3266 +/- ##
=======================================
Coverage 44.56% 44.56%
=======================================
Files 113 113
Lines 12194 12194
=======================================
Hits 5434 5434
Misses 5928 5928
Partials 832 832
Continue to review full report at Codecov.
|
|
Looks good to me |
|
I feel like these are rdwr to prevent broken pipe errors... but this is the shim log itself, so I'm not positive on that. |
|
Hi @cpuguy83 , if we use rdwr for shim log, we need to close the pipe during cleanup shim. I think the change might be easier. |
7be6024 to
84a92ab
Compare
I was thinking the v1 change has been covered by test case. Thanks @darfux |
84a92ab to
dea7391
Compare
@fuweid As you said we couldn't believe the test case always🤣. After debugging I find that shim v1 has fd leak as well due to a typo. And the test case doesn't get correct info from |
dea7391 to
6be24a5
Compare
Open shim v2 log with the flag `O_RDWR` will cause the `Read()` block forever even if the pipe has been closed on the shim side. Then the `io.Copy()` would never return and lead to a fd leak. Fix typo when closing shim v1 log which causes the `stdouLog` leak. Update `numPipes` function in test case to get the opened FIFO correctly. Signed-off-by: Li Yuxuan <liyuxuan04@baidu.com>
6be24a5 to
cf6e008
Compare
estesp
left a comment
There was a problem hiding this comment.
LGTM; great catch on the typo in v1 shim! @crosbymichael might want to comment on the lsof; could there be different versions of lsof that have changed the output?
|
LGTM |
|
I just added cherry-pick labels to this PR; I assume this is a pretty important bug fix that should go back to |
Open shim log with the flag
O_RDWRwill cause theRead()block forever even if the pipe has been closed on the shim side. Then theio.Copy()would never return and lead to a fd leak.It happens on both shim v1 and v2 but may only have effect on shim v2. Because when using shim v1 , the fd leak is on containerd-shim which will exit when the runtime shim exit. But under shim v2 the shim log is opened by the containerd process so the fd won't be closed until containerd exit.
Run a pod using shim v2 and
lsofon containerd:Then remove the pod,
lsofagain:Signed-off-by: Li Yuxuan liyuxuan04@baidu.com