Skip to content

changes to socket units don't restart #74899

Description

@domenkozar

#73871 attempted to fix this, but there were issues with sockets restarting all the time.

Activity

  1. added
    0.kind: bug
    6.topic: nixos
    on Dec 3, 2019
  2. griff commented on Jan 6, 2020

    @griff
    Contributor

    My PR #33661 explicitly ignored sockets where the unit had reloadIfChanged = true

  3. stale commented on Jul 4, 2020

    @stale

    Thank you for your contributions.

    This has been automatically marked as stale because it has had no activity for 180 days.

    If this is still important to you, we ask that you leave a comment below. Your comment can be as simple as "still important to me". This lets people see that at least one person still cares about this. Someone will have to do this at most twice a year if there is no other activity.

    Here are suggestions that might help resolve this more quickly:

    1. Search for maintainers and people that previously touched the related code and @ mention them in a comment.
    2. Ask on the NixOS Discourse.
    3. Ask on the #nixos channel on irc.freenode.net.
  4. added
    2.status: stale
    on Jul 4, 2020
  5. reopened this on Nov 28, 2021
  6. removed
    2.status: stale
    on Nov 28, 2021
  7. primeos commented on Nov 28, 2021

    @primeos
    Member

    Some quick notes:

    • IIRC the problem with restarting socket units was that the corresponding services will be restarted as well and options like systemd.services.<name>.stopIfChanged won't be respected (edit: not quite sure anymore if that's true, I'd need to re-check)
      • Possible solutions/workarounds
        • Propagate stopIfChanged, etc. from services to the socket units (but probably too difficult to get right)
        • Try to analyze Nixpkgs and apply the same settings to the socket units (likely too much work)
    • A NixOS VM test would help to catch such issues: Add NixOS desktop VM tests for "nixos-rebuild switch" #146809
    • For the next iteration of nixos/switch-to-configuration: Improve socket and timer handling, clean up, minor fixes, add test #141192:
      • Try to split the PR up into smaller PRs, if possible (I didn't have time for a closer look yet)
      • Try to make the restarting of socket units opt-in for now (via a env variable or flag)
      • Introduce a flag / env variable to restart all systemd units, even if they didn't change (I thing we'll really need that option for proper testing)
        • This should be incredibly useful for testing/reproducing as a nixos-rebuild switch normally depends on the last system state in that regard
      • Test the PR with Sway
  8. dasJ commented on Dec 10, 2021

    @dasJ
    Member

    So this is the new approach that I came up with and that was discussed with @ajs124, @lovesegfault, @roberth, and @flokli to improve it even further. I really hope this solves all issues we had and that it provides a proper way to handle all edge cases.

    So first off, there's a really easy case where the socket did not activate the service yet and something changed. We can restart just restart the socket if it changed and ignore all changes to the service file because it wasn't activated anyway. I don't think there's going to be any discussion about this detail of the implementation.

    The hard part comes around when the service was already activated at the point of the switch. We have 3 cases we need to handle which is "service modified", "socket modified", and "both modified".
    We can start with the easiest part that is just a plain modification of the service. If it has reloadIfChanged we can issue a reload of the service and we should be done. If it doesn't have reloadIfChanged we can stop it it has restartIfChanged set (this is where my old implementation lacked). We can ignore stopIfChanged in this case because it doesn't make sense.

    When the socket is changed but the service is not we have to take a look at restartIfChanged of the service and do nothing because people don't expect the service to be stopped at all which we would have to do. If the service is allowed to be restarted (restartIfChanged=true) we can take a look at stopIfChanged because that's what we are going to do now. Since this is true by default it should just give you the new behaviour by default which is to stop the socket, stop the service, and start the socket afterwards. There is no other way to prevent races between the service being stopped and the socket being restarted. If people want to opt out of this downtime-introducing feature they can do that by setting stopIfChanged=false.

    The last case is where both are changed. This is pretty similar to the "socket changed" case. If the service has restartIfChanged=false, do nothing yet again. Depending on stopIfChanged we can now decide what exactly to do next. If it is set to true (default), we can yet again stop the socket, stop the service, start the socket. If it is set to false however, we just stop (or reload if possible) the service and not do anything to the socket at all. This way the settings won't get applied to the socket but that might be preferrable in this case.

    I hope this all makes sense (I was about to draw a diagram but I couldn't find a proper way) and I'm happy to receive feedback on whether this is the best way to go. Assuming I can implement this without any bugs this should finally give us the requested behaviour.

  9. dasJ commented on Dec 10, 2021

    @dasJ
    Member

    Oh one thing to add is that if we stop the service, we can't do that in the regular "stopping the following services:" block but we would rather have to do it in a second stopping round that happens after the activation. If we don't do that, we get an annoying race where it's possible for the service to be activated and to load the old configuration before the activation is actually activated and /etc is rewritten. This should hopefully solve the problem @Ma27 was having with networkd and nixos containers

  10. added
    2.status: stale
    on Jun 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    0.kind: bug2.status: stale6.topic: nixos

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions