Skip to content

fix(warehouse): close load file descriptor in identity uploadFile - #7186

Merged
achettyiitr merged 2 commits into
rudderlabs:masterfrom
andyosyndoh:fix/identity-fd-leak-7185
Aug 17, 2026
Merged

achettyiitr merged 2 commits into
rudderlabs:masterfrom
andyosyndoh:fix/identity-fd-leak-7185

Conversation

@andyosyndoh

Copy link
Copy Markdown
Contributor

Description

uploadFile() in warehouse/identity/identity.go opened the load file for object-storage upload but never closed the file descriptor — on the filemanager-creation error path, the upload error path, or on success. Since uploadFile() runs twice per identity-resolution sync (merge rules + identity mappings), every sync leaked two file descriptors for the lifetime of the process, contributing to fd exhaustion (too many open files) under sustained syncing.

This PR:

  • adds defer func() { _ = outputFile.Close() }() immediately after the os.Open, matching the pattern used elsewhere in the package (identity.go tableRows.Close()) and in warehouse/validations/validate.go
  • replaces the panic(err) on open failure with a wrapped error return, consistent with every other error path in the function

Same defect class as #7071 (batchrouter), but in the identity-resolution flow.

Resolves #7185

Linear Ticket

N/A — community contribution, tracked in GitHub issue #7185

Security

  • The code changed/added as part of this pull request won't create any security issues with how the software is being used.

The load file opened in uploadFile() was never closed on any path,
leaking two file descriptors per identity-resolution sync. Also return
an error instead of panicking when the file cannot be opened, matching
the error handling of the rest of the function.

Resolves rudderlabs#7185
@contributor-support

Copy link
Copy Markdown

Thank you @andyosyndoh for contributing this PR.
Please sign the Contributor License Agreement (CLA) before merging.

@Aman-Chaturvedi-x78

Copy link
Copy Markdown

diff --git a/warehouse/identity/identity.go b/warehouse/identity/identity.go
index 83e523d..2867a5d 100644
--- a/warehouse/identity/identity.go
+++ b/warehouse/identity/identity.go
@@ -454,8 +454,10 @@ func (idr *Identity) writeTableToFile(tableName string, txn *sqlmiddleware.Tx, g
func (idr *Identity) uploadFile(ctx context.Context, filePath string, txn *sqlmiddleware.Tx, tableName string, totalRecords int) (err error) {
outputFile, err := os.Open(filePath)
if err != nil {

  •   panic(err)
    
  •   return fmt.Errorf("opening load file %s: %w", filePath, err)
    
    }
  • defer func() { _ = outputFile.Close() }()
  • storageProvider := warehouseutils.ObjectStorageType(idr.warehouse.Destination.DestinationDefinition.Name, idr.warehouse.Destination.Config, idr.uploader.UseRudderStorage())
    uploader, err := filemanager.New(&filemanager.Settings{
    Provider: storageProvider,

Comment thread warehouse/identity/identity.go Resolved
@achettyiitr

Copy link
Copy Markdown
Member

Everything looks good, merging then. #7279

@achettyiitr
achettyiitr merged commit 9693b0d into rudderlabs:master Aug 17, 2026
18 of 66 checks passed
atzoum added a commit that referenced this pull request Aug 18, 2026
# Description

Syncing release v1.83.0 to main branch

**WARNING: Do NOT rewrite git history and ALWAYS use a "Merge Commit"
for merging!**

**↓↓ Please review and edit commit overrides before merging ↓↓**

BEGIN_COMMIT_OVERRIDE
fix(warehouse): close load file descriptor in identity uploadFile
(#7186)
END_COMMIT_OVERRIDE
This was referenced Aug 24, 2026
itsmihir pushed a commit that referenced this pull request Aug 24, 2026
🤖 I have created a release *beep* *boop*
---


##
[1.84.0-rc.1](v1.83.0...v1.84.0-rc.1)
(2026-08-24)


### Features

* add AGENTS.md for agent management and reference
([#7290](#7290))
([2d28b32](2d28b32))
* **processor:** report duplicate events as dedup/filtered metrics
([#7280](#7280))
([f2655fb](f2655fb))
* **warehouse:** add clickhouse driver interface
([#7296](#7296))
([239d9a4](239d9a4))


### Bug Fixes

* **processor:** proc destination hydration omitted destination's
original id
([#7297](#7297))
([f389df4](f389df4))
* **warehouse:** close load file descriptor in identity uploadFile
([#7186](#7186))
([bfd8bc9](bfd8bc9))


### Miscellaneous

* handle oversized reporting payloads
([#7293](#7293))
([7a83281](7a83281))
* pyt security hardening
([#7272](#7272))
([e13b731](e13b731))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: rudderstack-github-actions[bot] <236995729+rudderstack-github-actions[bot]@users.noreply.github.com>
itsmihir pushed a commit that referenced this pull request Aug 25, 2026
🤖 I have created a release *beep* *boop*
---


##
[1.84.0](v1.83.0...v1.84.0)
(2026-08-24)


### Features

* add AGENTS.md for agent management and reference
([#7290](#7290))
([2d28b32](2d28b32))
* **processor:** report duplicate events as dedup/filtered metrics
([#7280](#7280))
([f2655fb](f2655fb))
* **warehouse:** add clickhouse driver interface
([#7296](#7296))
([239d9a4](239d9a4))


### Bug Fixes

* **processor:** proc destination hydration omitted destination's
original id
([#7297](#7297))
([f389df4](f389df4))
* **warehouse:** close load file descriptor in identity uploadFile
([#7186](#7186))
([bfd8bc9](bfd8bc9))


### Miscellaneous

* handle oversized reporting payloads
([#7293](#7293))
([7a83281](7a83281))
* pyt security hardening
([#7272](#7272))
([e13b731](e13b731))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: rudderstack-github-actions[bot] <236995729+rudderstack-github-actions[bot]@users.noreply.github.com>
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.

bug(warehouse/identity): file descriptor leak in uploadFile() — outputFile never closed

4 participants