Skip to content

Conversation

@khvn26
Copy link
Member

@khvn26 khvn26 commented Nov 5, 2025

In this PR, we change the following:

  1. Use a default stable path for PROMETHEUS_MULTIPROC_DIR instead of relying on a random one offered by tempfile.mkdtemp to completely avoid new directories spam reported in temporary directories are not removed flagsmith#5990.
  2. Move the cleanup to app startup. This ensures that the directory exists throughout Gunicorn's worker lifecycle.

@khvn26 khvn26 requested a review from a team as a code owner November 5, 2025 12:10
@khvn26 khvn26 requested review from emyller and removed request for a team November 5, 2025 12:10
@codecov-commenter
Copy link

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.65%. Comparing base (00a973a) to head (e181d86).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #116      +/-   ##
==========================================
- Coverage   94.67%   94.65%   -0.02%     
==========================================
  Files          76       77       +1     
  Lines        2479     2470       -9     
==========================================
- Hits         2347     2338       -9     
  Misses        132      132              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor

@emyller emyller left a comment

Choose a reason for hiding this comment

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

I don't have context yet, but I'm interested in possibly cleaning up temporary files on startup (just in case the previous run ended unexpectedly), and on shutdown (because it's polite to cleanup resources after use).

Unless there's reason I don't know, the better approach to manage temporary files should be via tempfile as long as we always cleanup.

Comment on lines +131 to +148
def test_main__prometheus_multiproc_remove_dir_on_start_true__expected(
monkeypatch: pytest.MonkeyPatch,
fs: FakeFilesystem,
) -> None:
# Given
monkeypatch.delenv("PROMETHEUS_MULTIPROC_DIR")
monkeypatch.delenv("PROMETHEUS_MULTIPROC_DIR", raising=False)
monkeypatch.setenv("PROMETHEUS_MULTIPROC_DIR_KEEP", "true")

fs.create_file(
"/tmp/flagsmith-prometheus/some_metric_file.db",
create_missing_dirs=True,
)

# When
main(["flagsmith"])

# Then
assert Path(os.environ["PROMETHEUS_MULTIPROC_DIR"]).exists()
assert fs.exists("/tmp/flagsmith-prometheus/some_metric_file.db")
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this use case real? i.e. Is there a reason why we need to keep the temporary files generated by this program?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants