Skip to content

Make the gunicorn API server respect GUNICORN_CMD_ARGS again#62522

Merged
ashb merged 1 commit intoapache:mainfrom
astronomer:apiserver-respect-gunicorn-cmd-args-again
Feb 26, 2026
Merged

Make the gunicorn API server respect GUNICORN_CMD_ARGS again#62522
ashb merged 1 commit intoapache:mainfrom
astronomer:apiserver-respect-gunicorn-cmd-args-again

Conversation

@ashb
Copy link
Member

@ashb ashb commented Feb 26, 2026

Since our new Arbiter and custom code added in #60940 doesn't invoke Gunicorn via the full CLI path of normal gunicorn, we have to manually call this.

This lets us give control to users to accept any and all gunicorn args without us having to put them in our CLI, or keep up to date with changes. This env var is something stock gunicorn already respects too.

Tested with AIRFLOW__API__SERVER_TYPE=gunicorn GUNICORN_CMD_ARGS="--max-requests 2" airflow api-server

And then after two requests we see this:

[2026-02-26 14:25:30 +0000] [91022] [INFO] Maximum request limit of 2 exceeded. Terminating process.
[2026-02-26 14:25:30 +0000] [91022] [INFO] Shutting down
[2026-02-26 14:25:30 +0000] [91022] [INFO] Waiting for application shutdown.
[2026-02-26 14:25:30 +0000] [91022] [INFO] Application shutdown complete.
[2026-02-26 14:25:30 +0000] [91022] [INFO] Finished server process [91022]
[2026-02-26 14:25:30 +0000] [91022] [INFO] Worker exiting (pid: 91022)
[2026-02-26 14:25:31 +0000] [91026] [INFO] Booting worker with pid: 91026
[2026-02-26 14:25:31 +0000] [91026] [INFO] Started server process [91026]
[2026-02-26 14:25:31 +0000] [91026] [INFO] Waiting for application startup.
[2026-02-26 14:25:31 +0000] [91026] [INFO] Application startup complete.

@ashb ashb added the backport-to-v3-1-test Mark PR with this label to backport to v3-1-test branch label Feb 26, 2026
Copy link
Member

@kaxil kaxil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nits

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR restores support for the GUNICORN_CMD_ARGS environment variable in the Airflow API server when using gunicorn. This functionality was broken after the introduction of a custom Arbiter in PR #60940, which bypassed gunicorn's normal CLI parsing. The fix manually invokes gunicorn's environment variable parsing API to respect user-provided gunicorn arguments.

Changes:

  • Modified load_config() to parse and apply GUNICORN_CMD_ARGS environment variable settings
  • Added comprehensive test coverage for the new functionality including precedence rules
  • Ensured environment variables override programmatic options (consistent with standard behavior)

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
airflow-core/src/airflow/api_fastapi/gunicorn_app.py Added code to parse GUNICORN_CMD_ARGS and apply settings to gunicorn config
airflow-core/tests/unit/cli/commands/test_gunicorn_monitor.py Added three tests verifying config loading, GUNICORN_CMD_ARGS support, and precedence rules

Since our new Arbiter and custom code doesn't invoke Gunicorn via the full CLI
path of normal gunicorn, we have to manually call this.

This lets us give control to users to accept any and all gunicorn args without
us having to put them in our CLI, or keep up to date with changes. This env
var is something stock `gunicorn` already respects too.
@ashb ashb force-pushed the apiserver-respect-gunicorn-cmd-args-again branch from cd0921e to 5c5175b Compare February 26, 2026 15:33
@ashb ashb merged commit 67a86d5 into apache:main Feb 26, 2026
129 checks passed
@ashb ashb deleted the apiserver-respect-gunicorn-cmd-args-again branch February 26, 2026 17:26
@github-actions
Copy link

Backport failed to create: v3-1-test. View the failure log Run details

Note: As of Merging PRs targeted for Airflow 3.X
the committer who merges the PR is responsible for backporting the PRs that are bug fixes (generally speaking) to the maintenance branches.

In matter of doubt please ask in #release-management Slack channel.

Status Branch Result
v3-1-test Commit Link

You can attempt to backport this manually by running:

cherry_picker 67a86d5 v3-1-test

This should apply the commit to the v3-1-test branch and leave the commit in conflict state marking
the files that need manual conflict resolution.

After you have resolved the conflicts, you can continue the backport process by running:

cherry_picker --continue

If you don't have cherry-picker installed, see the installation guide.

@github-actions github-actions bot added this to the Airflow 3.1.8 milestone Feb 26, 2026
@github-actions
Copy link

Hi maintainer, this PR was merged without a milestone set.
We've automatically set the milestone to Airflow 3.1.8 based on: backport label targeting v3-1-test
If this milestone is not correct, please update it to the appropriate milestone.

This comment was generated by Milestone Tag Assistant.

AkshayArali pushed a commit to AkshayArali/airflow_630 that referenced this pull request Feb 28, 2026
…62522)

Since our new Arbiter and custom code doesn't invoke Gunicorn via the full CLI
path of normal gunicorn, we have to manually call this.

This lets us give control to users to accept any and all gunicorn args without
us having to put them in our CLI, or keep up to date with changes. This env
var is something stock `gunicorn` already respects too.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:CLI backport-to-v3-1-test Mark PR with this label to backport to v3-1-test branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants