You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What I think is happening is when pid1 reexecutes it drops the varlink connection. systemd-oomd as part of its event loop will immediately try to connect again. But if pid1 isn't done reexecuting by the time systemd-oomd tries again we get "Connection refused" and hard fail.
I'm not sure if there's a way to distinguish between pid1 reexecuting and inability to connect to pid1 due to some other error. I was able to repro and in all cases systemd-oomd restarts due to Restart=on-failure and successfully reconnected afterwards so it doesn't seem like a huge problem.
What I think is happening is when pid1 reexecutes it drops the varlink connection.
Yep, that sounds right.
it doesn't seem like a huge problem.
Well, it looks very ugly.
One option would be to stop systemd-oomd before reexecuting and restart if afterwards. But that's super ugly.
I think the right solution would be to try to connect to /run/systemd/io.system.ManagedOOM, and it we get ENOENT, try again after a small exponentially-increasing delay, up to some timeout. @poettering other ideas?
We could keep the lstening fd open i guess, so that we remain connectable all the time. that would mean ongoing connections might be dropped, but you can intstantly create a new one, and it would be sfaely handled.
(in fact, i assumed we already do it that way: serialize the varlink listener fd, and pass it from the old to the new instance without closing it)
and waiting for daemon-reexec. Once the script is subscribed systemd-oomd unsuccessfully keeps trying to subscribe and failing:
Aug 10 00:44:35 C systemd-oomd[2928]: oomd: Sending message: {"method":"io.systemd.ManagedOOM.SubscribeManagedOOMCGroups","parameters":{},"more":true}
Aug 10 00:44:35 C systemd-oomd[2928]: oomd: Changing state idle-client → awaiting-reply-more
Aug 10 00:44:35 C systemd-oomd[2928]: oomd: New incoming message: {"error":"org.varlink.service.SubscriptionTaken","parameters":{}}
Aug 10 00:44:35 C systemd-oomd[2928]: oomd: Changing state awaiting-reply-more → processing-reply
Aug 10 00:44:35 C systemd-oomd[2928]: Error getting ManagedOOM cgroups: org.varlink.service.SubscriptionTaken
Aug 10 00:44:35 C systemd-oomd[2928]: oomd: Changing state processing-reply → disconnected
Aug 10 00:44:35 C systemd-oomd[2928]: Reply callback returned error, ignoring: Input/output error
Aug 10 00:44:35 C systemd-oomd[2928]: varlink: Setting state idle-client
Aug 10 00:44:35 C systemd-oomd[2928]: oomd: Sending message: {"method":"io.systemd.ManagedOOM.SubscribeManagedOOMCGroups","parameters":{},"more":true}
Aug 10 00:44:35 C systemd-oomd[2928]: oomd: Changing state idle-client → awaiting-reply-more
Aug 10 00:44:35 C systemd-oomd[2928]: oomd: New incoming message: {"error":"org.varlink.service.SubscriptionTaken","parameters":{}}
Aug 10 00:44:35 C systemd-oomd[2928]: oomd: Changing state awaiting-reply-more → processing-reply
Aug 10 00:44:35 C systemd-oomd[2928]: Error getting ManagedOOM cgroups: org.varlink.service.SubscriptionTaken
Aug 10 00:44:35 C systemd-oomd[2928]: oomd: Changing state processing-reply → disconnected
Aug 10 00:44:35 C systemd-oomd[2928]: Reply callback returned error, ignoring: Input/output error
Aug 10 00:44:36 C systemd-oomd[2928]: varlink: Setting state idle-client
FWIW it's possible for unprivileged users to somewhat "turn off" systemd-oomd by running the following script
Well that's unfortunate. I wonder if this is happening because we added the ability for user managers to also set ManagedOOM*= properties. I'll have to try this out myself. Does this only affect systemd-oomd when operating on user manager units? Or does it affect subscriptions to the system manager units too?
I had a look at fixing this by serializing the varlink server fds during reexec, but I'm unsure on the best way to go about it. We need to add a way to get the corresponding socket fd from the varlink server. Should we add a description to varlink server sockets and allow querying sockets by description so that we can serialize the socket along with its description?
There should be only one listener fd for the oomd stuff. hence I'd just add a call varlink_server_get_listen_fd() or so, and it returns -ENOTUNIQ if more than one listener is in place. Then, when serializing you just take that, and add it to the serialization fdset (which will implicitly dup it). Then, when deserializing things, you pass it to a new varlink server via varlink_server_listen_fd()
I have a working draft that naively serializes/dups all the FDs in pid1's VarlinkServer (which deals with the immediate problem I guess). Once the deserializing is properly sorted out I should have a PR up. I think to distinguish the FDs we can fill out the address string? It doesn't appear to be set at the moment
Activity
anitazha commentedon Jul 29, 2021
What I think is happening is when pid1 reexecutes it drops the varlink connection. systemd-oomd as part of its event loop will immediately try to connect again. But if pid1 isn't done reexecuting by the time systemd-oomd tries again we get "Connection refused" and hard fail.
I'm not sure if there's a way to distinguish between pid1 reexecuting and inability to connect to pid1 due to some other error. I was able to repro and in all cases systemd-oomd restarts due to
Restart=on-failureand successfully reconnected afterwards so it doesn't seem like a huge problem.keszybz commentedon Jul 29, 2021
Yep, that sounds right.
Well, it looks very ugly.
One option would be to stop systemd-oomd before reexecuting and restart if afterwards. But that's super ugly.
I think the right solution would be to try to connect to
/run/systemd/io.system.ManagedOOM, and it we get ENOENT, try again after a small exponentially-increasing delay, up to some timeout. @poettering other ideas?poettering commentedon Jul 29, 2021
We could keep the lstening fd open i guess, so that we remain connectable all the time. that would mean ongoing connections might be dropped, but you can intstantly create a new one, and it would be sfaely handled.
(in fact, i assumed we already do it that way: serialize the varlink listener fd, and pass it from the old to the new instance without closing it)
evverx commentedon Aug 10, 2022
FWIW it's possible for unprivileged users to somewhat "turn off"
systemd-oomdby running the following scriptand waiting for
daemon-reexec. Once the script is subscribedsystemd-oomdunsuccessfully keeps trying to subscribe and failing:Aug 10 00:44:35 C systemd-oomd[2928]: oomd: Sending message: {"method":"io.systemd.ManagedOOM.SubscribeManagedOOMCGroups","parameters":{},"more":true} Aug 10 00:44:35 C systemd-oomd[2928]: oomd: Changing state idle-client → awaiting-reply-more Aug 10 00:44:35 C systemd-oomd[2928]: oomd: New incoming message: {"error":"org.varlink.service.SubscriptionTaken","parameters":{}} Aug 10 00:44:35 C systemd-oomd[2928]: oomd: Changing state awaiting-reply-more → processing-reply Aug 10 00:44:35 C systemd-oomd[2928]: Error getting ManagedOOM cgroups: org.varlink.service.SubscriptionTaken Aug 10 00:44:35 C systemd-oomd[2928]: oomd: Changing state processing-reply → disconnected Aug 10 00:44:35 C systemd-oomd[2928]: Reply callback returned error, ignoring: Input/output error Aug 10 00:44:35 C systemd-oomd[2928]: varlink: Setting state idle-client Aug 10 00:44:35 C systemd-oomd[2928]: oomd: Sending message: {"method":"io.systemd.ManagedOOM.SubscribeManagedOOMCGroups","parameters":{},"more":true} Aug 10 00:44:35 C systemd-oomd[2928]: oomd: Changing state idle-client → awaiting-reply-more Aug 10 00:44:35 C systemd-oomd[2928]: oomd: New incoming message: {"error":"org.varlink.service.SubscriptionTaken","parameters":{}} Aug 10 00:44:35 C systemd-oomd[2928]: oomd: Changing state awaiting-reply-more → processing-reply Aug 10 00:44:35 C systemd-oomd[2928]: Error getting ManagedOOM cgroups: org.varlink.service.SubscriptionTaken Aug 10 00:44:35 C systemd-oomd[2928]: oomd: Changing state processing-reply → disconnected Aug 10 00:44:35 C systemd-oomd[2928]: Reply callback returned error, ignoring: Input/output error Aug 10 00:44:36 C systemd-oomd[2928]: varlink: Setting state idle-clientanitazha commentedon Aug 10, 2022
Well that's unfortunate. I wonder if this is happening because we added the ability for user managers to also set ManagedOOM*= properties. I'll have to try this out myself. Does this only affect systemd-oomd when operating on user manager units? Or does it affect subscriptions to the system manager units too?
evverx commentedon Aug 10, 2022
As far as I can tell among other things the script prevents
systemd-oomdfrom receiving messages like{ "parameters": { "cgroups": [ { "mode": "auto", "path": "/system.slice/systemd-oomd.service", "property": "ManagedOOMSwap" }, { "mode": "auto", "path": "/system.slice/systemd-oomd.service", "property": "ManagedOOMMemoryPressure", "limit": 0 } ] }, "continues": true } { "parameters": { "cgroups": [ { "mode": "auto", "path": "/system.slice/system-container\\x2dshell.slice/[email protected]", "property": "ManagedOOMSwap" }, { "mode": "auto", "path": "/system.slice/system-container\\x2dshell.slice/[email protected]", "property": "ManagedOOMMemoryPressure" } ] }, "continues": true }so it seems it affects subscriptions to the system manager units too.
daandemeyer commentedon Sep 30, 2022
I had a look at fixing this by serializing the varlink server fds during reexec, but I'm unsure on the best way to go about it. We need to add a way to get the corresponding socket fd from the varlink server. Should we add a description to varlink server sockets and allow querying sockets by description so that we can serialize the socket along with its description?
poettering commentedon Sep 30, 2022
There should be only one listener fd for the oomd stuff. hence I'd just add a call varlink_server_get_listen_fd() or so, and it returns -ENOTUNIQ if more than one listener is in place. Then, when serializing you just take that, and add it to the serialization fdset (which will implicitly dup it). Then, when deserializing things, you pass it to a new varlink server via varlink_server_listen_fd()
daandemeyer commentedon Sep 30, 2022
But there's also the dynamic user varlink stuff, thus we need to have a way to ask for the right fd from the varlink server
anitazha commentedon Oct 3, 2022
I have a working draft that naively serializes/dups all the FDs in pid1's VarlinkServer (which deals with the immediate problem I guess). Once the deserializing is properly sorted out I should have a PR up. I think to distinguish the FDs we can fill out the address string? It doesn't appear to be set at the moment
core: serialize/deserialize varlink sockets for pid1
4 remaining items
core: only allow systemd-oomd to use SubscribeManagedOOMCGroups
core: serialize/deserialize varlink sockets for pid1
core: only allow systemd-oomd to use SubscribeManagedOOMCGroups
core: only allow systemd-oomd to use SubscribeManagedOOMCGroups
core: serialize/deserialize varlink sockets for pid1
core: only allow systemd-oomd to use SubscribeManagedOOMCGroups
core: serialize/deserialize varlink sockets for pid1
core: only allow systemd-oomd to use SubscribeManagedOOMCGroups
core: serialize/deserialize varlink sockets for pid1
core: only allow systemd-oomd to use SubscribeManagedOOMCGroups
Merge pull request #24919 from anitazha/varlinkserialize
core: only allow systemd-oomd to use SubscribeManagedOOMCGroups
core: only allow systemd-oom user to use SubscribeManagedOOMCGroups