Skip to content

Fix audit middleware file handle leak on shutdown#3074

Merged
jhrozek merged 2 commits intomainfrom
audit_leak_shutdown
Feb 5, 2026
Merged

Fix audit middleware file handle leak on shutdown#3074
jhrozek merged 2 commits intomainfrom
audit_leak_shutdown

Conversation

@jhrozek
Copy link
Copy Markdown
Contributor

@jhrozek jhrozek commented Dec 16, 2025

Store Auditor reference in Middleware struct to enable proper cleanup. Update Close() to call Auditor.Close() for file-based logging. Use NewAuditorWithTransport directly instead of CreateMiddlewareWithTransport.

This ensures audit log file handles are properly closed when the runner shuts down, preventing resource leaks and ensuring logs are flushed.

@github-actions github-actions Bot added size/XS Extra small PR: < 100 lines changed and removed size/XS Extra small PR: < 100 lines changed labels Dec 16, 2025
@codecov
Copy link
Copy Markdown

codecov Bot commented Dec 16, 2025

Codecov Report

❌ Patch coverage is 71.42857% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 63.76%. Comparing base (f0b59a9) to head (b75b68f).
⚠️ Report is 236 commits behind head on main.

Files with missing lines Patch % Lines
pkg/audit/middleware.go 71.42% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3074      +/-   ##
==========================================
+ Coverage   63.66%   63.76%   +0.10%     
==========================================
  Files         360      360              
  Lines       35328    35322       -6     
==========================================
+ Hits        22491    22523      +32     
+ Misses      11030    10992      -38     
  Partials     1807     1807              

☔ 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.

JAORMX
JAORMX previously approved these changes Jan 12, 2026
Store Auditor reference in Middleware struct to enable proper cleanup.
Update Close() to call Auditor.Close() for file-based logging.
Use NewAuditorWithTransport directly instead of CreateMiddlewareWithTransport.

This ensures audit log file handles are properly closed when the runner
shuts down, preventing resource leaks and ensuring logs are flushed.
Delete CreateMiddlewareWithTransport and GetMiddlewareFromFile functions
along with their tests. These functions had a design flaw where they
created an Auditor but only returned the middleware function, making it
impossible for callers to close file handles.

The CreateMiddleware factory now calls NewAuditorWithTransport directly,
making these wrapper functions unnecessary.
@jhrozek jhrozek force-pushed the audit_leak_shutdown branch from ad1d879 to b75b68f Compare January 13, 2026 14:08
@github-actions github-actions Bot added size/XS Extra small PR: < 100 lines changed and removed size/XS Extra small PR: < 100 lines changed labels Jan 13, 2026
@JAORMX
Copy link
Copy Markdown
Collaborator

JAORMX commented Feb 3, 2026

@jhrozek,

This has been approved and sitting here for a few weeks now. The only failing check is the E2E test on K8s v1.34.3, but it passes on v1.33.7 and v1.35.0. Looks like a flaky test rather than anything related to this change.

Want to rebase and re-run CI to get this merged?

@jhrozek jhrozek merged commit 9c87519 into main Feb 5, 2026
44 of 46 checks passed
@jhrozek jhrozek deleted the audit_leak_shutdown branch February 5, 2026 00:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/XS Extra small PR: < 100 lines changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants