Skip to content

Conversation

@pajod
Copy link
Contributor

@pajod pajod commented Aug 23, 2024

This PR stops mangling sys.argv and socket fd numbers on re-exec, thus permitting much improved integration with systemd.

  • While not meant to break anything before that, this patch is only effective in cPython >= 3.10.
    • Python docs explicitly say that relaunching with -m switch is the recommended procedure, so that should work
diff --git a/gunicorn/arbiter.py b/gunicorn/arbiter.py
-        args = sys.argv[:]
-        args.insert(0, sys.executable)
+        if sys.version_info < (3, 10):
+            args = sys.argv[:]
+            args.insert(0, sys.executable)
+        else:
+            args = sys.orig_argv[:]

@pajod pajod moved this to Awaiting: 1st review in @pajod Gunicorn issue sorting table Mar 21, 2025
@pajod pajod changed the title Use original arguments on arbiter re-exec, and tell systemd so exiting old master does not terminate service Retain argv + fds on re-exec, notify about MAINPID to fix USR2 under systemd Apr 10, 2025
@pajod pajod changed the title Retain argv + fds on re-exec, notify about MAINPID to fix USR2 under systemd Retain argv + fds on re-exec, fix USR2 under systemd by notifying new PID Apr 10, 2025
@pajod pajod marked this pull request as ready for review April 10, 2025 14:14
@benoitc
Copy link
Owner

benoitc commented Oct 5, 2025

what , does thsi patch exactly in simple word and how do you guarantee the compatibility with current systems not running systemd?

@pajod
Copy link
Contributor Author

pajod commented Oct 10, 2025

This PR is a superset of #3419 and I will rebase and fix it once that one is merged.

what , does thsi patch exactly in simple word

Use fd numbers and argv as-is, and keep systemd informed about status changes.

how do you guarantee the compatibility with current systems not running systemd

The status changes are effectively no-op outside of systemd, so only 3 changes remain to be judged in that regard:

  1. using original argv is the same except for one special case -- one probably nobody used, as suggested by me being 1st to complain about the crash
  2. not duplicating file descriptors on re-exec and the fd:// setting -- getting exactly the same thing is the point of duplication. If that operation changed things, it would not really be a "duplicate"
  3. extra warning -- only emitted on very clearly unintended configuration. also, its just one extra line logged per master startup, should not cause compat issues.

I deliberately did not guard these 3 changes behind a if systemd: branch, because they resolve issues that are merely unlikely to be encountered outside of systemd, not specific to systemd.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants