-
Notifications
You must be signed in to change notification settings - Fork 18.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Close pipe in overlay2 graphdriver #34863
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
ping @kolyshkin |
LGTM |
daemon/graphdriver/overlay2/mount.go
Outdated
@@ -57,7 +58,6 @@ func mountFrom(dir, device, target, mType string, flags uintptr, label string) e | |||
if err := json.NewEncoder(w).Encode(options); err != nil { | |||
return fmt.Errorf("mountfrom json encode to pipe failed: %v", err) | |||
} | |||
w.Close() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The close was explicitly called before Wait
to ensure that the process is not waiting on additional input.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In that case, should a w.Close()
be put inside the err ifs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And probably a comment added to prevent someone from changing to a defer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@thaJeztah I think it is more a matter of style, I prefer to have w.Close
inside the if statements but calling w.Close
multiple times (one before Wait, and one on defer) is not a problem.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, before putting my LGTM I wrote a test program to check whether json decoder would wait on input if it's not closed. Apparently as soon as json data goes through it proceeds even if stdin is still open. |
@dmcgowan @kolyshkin @thaJeztah @yongtang @vieux thanks for your reviews. I see go's code for cmd.Wait(), I think process will not block if reexec process exit, becuase fd.Close() will not block.
I also have the following code to test,
the output:
So I agree with @kolyshkin, can we still use defer close ,WDYT ? |
It works without explicit Close(), as json.Decode() finishes as long as the document is complete (last closing bracket is received). Still, an extra Close() before Wait() looks cleaner to me. |
Signed-off-by: Shukui Yang <yangshukui@huawei.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
all green; merging |
LOL looks like we pressed the button at the same time |
😄 👍 🍺 |
FIX DTS2017091508576 upstream pr moby#34863 Signed-off-by: yangshukui <yangshukui@huawei.com>
Use defer to close pipe FIX DTS2017091508576 upstream pr moby#34863 Signed-off-by: yangshukui <yangshukui@huawei.com> See merge request docker/docker!759
If cmd.Start() fail in mountFrom, we will have pipe not closed.
Reported-by:Qiang Ning ningqiang1@huawei.com
Signed-off-by: Shukui Yang yangshukui@huawei.com