-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
notify_socket.go: use sd_notify_barrier mechanism #3291
Conversation
bfcf6b9
to
4cd4337
Compare
Please squash commits |
4cd4337
to
f109dab
Compare
Overall this looks good to me. Is there any way to have a test for this @indyjo ? |
What I can imagine is to write a test against a mocked NOTIFY_SOCKET server, i.e. a mocked systemd. Concerning how to do it I think I need some guidance. I could try adding a Also, my code is currently assuming that whoever listens on the other end of NOTIFY_SOCKET actually understands and honors the Is this behavior a) accepted or should I b) ignore the timeout case or should there be c) a command-line option to suppress the sd_notify_barrier feature? |
0ebabd7
to
f317259
Compare
f317259
to
007af91
Compare
notify_socket.go
Outdated
var out bytes.Buffer | ||
_, err := out.Write(ready) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
_, err = client.Write(out.Bytes()) | ||
if err != nil { | ||
return err | ||
} | ||
_, err = out.Write([]byte{'\n'}) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// now we can inform systemd to use pid1 as the pid to monitor | ||
newPid := "MAINPID=" + strconv.Itoa(pid1) | ||
_, err := client.Write([]byte(newPid + "\n")) | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} | ||
_, err = client.Write(out.Bytes()) |
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.
Hmm, wonder why we avoid using bytes.Buffer at all and don't just do something like
_, err = client.WriteString(string(ready)+"\n")
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 is no WriteString
on client
but of course we can change to:
_, err = io.WriteString(client, string(ready) + "\n")
or, more directly:
_, err = client.Write([]byte(string(ready) + "\n"))
or, more efficient but mutating the array backing ready
:
_, err = client.Write(append(ready, '\n'))
Any preference?
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.
Hmm, wonder why we avoid using bytes.Buffer at all
Looking at git history, this was done in #1308 but I don't see why.
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.
_, err = client.Write(append(ready, '\n'))
This one looks fine to me (most probably there's \n
already anyway at that position), as we are not reusing the buffer anywhere.
Can you implement it (as a separate first commit, I guess)?
@indyjo thanks for the update! Can you please
|
I'm asking for this because it makes the git log -p smaller (and, consequently, it will be easier to figure out what was changed, especially a few years from now). |
50ab174
to
a0aca43
Compare
Thanks for clarifying, @kolyshkin! The two commits are now in the preferred order. Should we discuss how to handle the case where the supervising process doesn't (correctly) handle the |
I tend to agree.
I guess on an overloaded system 5s might not be enough, so the timeout should be way above the reasonable expected reply time. But let's ask @giuseppe -- why you ended up with 30s timeout? |
I've copied the timeout you set here: https://github.com/opencontainers/runc/blob/master/libcontainer/cgroups/systemd/common.go#L345 😄 Although I've decided to ignore any error, so it is equivalent to the version without |
@AkihiroSuda PTAL |
@opencontainers/runc-maintainers PTAL |
@opencontainers/runc-maintainers @AkihiroSuda PTAL |
Does it really make sense to implement the barrier-machanism inside of runc?
My implementation idea would be to also relay SCM_RIGHT data and let the client and systemd handle the synchronization transparently. |
Hi @MofX, let me give my point of view. And sorry about it taking so long. First of all, whether this patch ends up in an official release or not is not absolutely critical for me. The company I work for, KUKA, maintains their own patched version of
Probably true. The protocol basically mandates the use of the barrier, though. There is no way for a client to query whether it's supported. Concerning your point 2 and 3: I don't know enough about Actually, we never observed any timeout happening in |
@kolyshkin May I ask if there's a chance of including this in v1.1.2? |
The target milestone is set for 1.2.0 (which I hope will be released some time in the summer). We can definitely do a backport to 1.1.x once this is merged, and so it will also be included into latest 1.1.x (whatever that would be). We need more reviews on this, @opencontainers/runc-maintainers PTAL 🙏🏻 |
@indyjo can you please rebase it (this will also re-run the CI on golang 1.18)? |
0eff971
to
f4f5996
Compare
@kolyshkin Technically, it's done. There's a failing check though: |
Friendly reminder that there's still a chance for this baby to be merged before its first birthday! 🎂 |
The last rebase was 6 months ago, could you rebase again to ensure CI is still green? Thanks |
Signed-off-by: Jonas Eschenburg <jonas.eschenburg@kuka.com>
Signed-off-by: Jonas Eschenburg <jonas.eschenburg@kuka.com>
f4f5996
to
067ca8f
Compare
Rebased and green. @AkihiroSuda @kolyshkin |
@kolyshkin Just a friendly reminder |
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
Add synchronization to how runc reports container readiness to systemd.
It was previously possible for runc to terminate immediately after sending the READY signal. This was sometimes too quick for systemd to find out the sender's cgroup. As a consequence, systemd would ignore the READY signal.
Fixes: #3293