Skip to content

fix(batchrouter): file descriptor leak in upload() — outputFile never closed - #7106

Closed
kuntal1461 wants to merge 2 commits into
rudderlabs:masterfrom
kuntal1461:fix/batchrouter-fd-leak-upload
Closed

kuntal1461 wants to merge 2 commits into
rudderlabs:masterfrom
kuntal1461:fix/batchrouter-fd-leak-upload

Conversation

@kuntal1461

@kuntal1461 kuntal1461 commented Jun 20, 2026

Copy link
Copy Markdown

Closes #7071

Summary

outputFile is opened via os.Open(gzipFilePath) in Handle.upload() but never closed — leaking one file descriptor on every batch upload call, on both the success and error return paths.

Fix

Added defer func() { _ = outputFile.Close() }() immediately after os.Open, matching the existing pattern in archiver/worker.go:187.

outputFile, err := os.Open(gzipFilePath)
if err != nil {
    panic(err)
}
defer func() { _ = outputFile.Close() }()  // ← added

Impact without fix

upload() is called on every batch job cycle for every active destination. Each call leaks one fd. Under sustained load this exhausts the process fd limit (ulimit -n), causing too many open files errors — dropped events or a crashed process.

Test plan

  • go test ./router/batchrouter/... passes
  • No new linter warnings

@github-actions

Copy link
Copy Markdown
Contributor

This PR is considered to be stale. It has been open 20 days with no further activity thus it is going to be closed in 7 days. To avoid such a case please consider removing the stale label manually or add a comment to the PR.

@github-actions github-actions Bot added the Stale label Jul 11, 2026

@Rebaka8 Rebaka8 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Verified that the deferred outputFile.Close() is placed immediately after os.Open(), ensuring the file descriptor is released on both successful and error execution paths. The implementation is minimal, addresses the reported resource leak, and follows the existing resource cleanup pattern used elsewhere in the project. Looks good to me.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(batchrouter): file descriptor leak in upload() — outputFile never closed

2 participants