Skip to content

oomd fails during pid1 daemon-reexec #20330

Closed

Description

@keszybz

When I do 'systemctl daemon-reexec' in a Fedora rawhide VM, I get:

Jul 28 11:52:54 rawhide-uefi systemd-oomd[685]: Failed to connect to /run/systemd/io.system.ManagedOOM: Connection refused
Jul 28 11:52:54 rawhide-uefi systemd-oomd[685]: Failed to acquire varlink connection: Connection refused
Jul 28 11:52:54 rawhide-uefi systemd-oomd[685]: Event loop failed: Connection refused

This seems fairly repeatable and I have also seen it in other places…

/cc @anitazha

Activity

  1. anitazha commented on Jul 29, 2021

    @anitazha
    Member

    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.

  2. keszybz commented on Jul 29, 2021

    @keszybz
    MemberAuthor

    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?

  3. poettering commented on Jul 29, 2021

    @poettering
    Member

    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)

  4. self-assigned this
    on Aug 3, 2021
  5. evverx commented on Aug 10, 2022

    @evverx
    Contributor

    FWIW it's possible for unprivileged users to somewhat "turn off" systemd-oomd by running the following script

    while :; do
        printf '
    {
      "method": "io.systemd.ManagedOOM.SubscribeManagedOOMCGroups",
      "parameters": {},
      "more": true
    }\0' | ncat -U /run/systemd/io.system.ManagedOOM;
    done

    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
  6. anitazha commented on Aug 10, 2022

    @anitazha
    Member

    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?

  7. evverx commented on Aug 10, 2022

    @evverx
    Contributor

    As far as I can tell among other things the script prevents systemd-oomd from 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.

  8. added
    bug 🐛
    on Aug 10, 2022
  9. added this to the v252 milestone on Aug 11, 2022
  10. daandemeyer commented on Sep 30, 2022

    @daandemeyer
    Collaborator

    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?

  11. poettering commented on Sep 30, 2022

    @poettering
    Member

    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()

  12. daandemeyer commented on Sep 30, 2022

    @daandemeyer
    Collaborator

    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

  13. anitazha commented on Oct 3, 2022

    @anitazha
    Member

    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

  14. added a commit that references this issue on Oct 7, 2022
    2d3a3e5
  15. 4 remaining items

  16. added 9 commits that reference this issue on Oct 11, 2022
    88ad7f2
    2e9eadc
    0f68c7d
    db7faea
    7377cd8
    e2f3d4c
    5e1f33b
    008798e
    2842128
  17. added a commit that references this issue on Oct 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug 🐛oomd

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions