Skip to content

File descriptor not closed on remote bucket.upload() errors #2706

@MartinKolarik

Description

@MartinKolarik

Please make sure you have searched for information in the following guides.

A screenshot that you have tested with "Try this API".

N/A, the bug is in the client code.

Link to the code that reproduces this issue. A link to a public Github Repository or gist with a minimal reproduction.

https://gist.github.com/MartinKolarik/04bcb1ac4209d3afee62a31667f666d7

A step-by-step description of how to reproduce the issue, based on the linked reproduction.

  1. Create a large local file.
  2. Start bucket.upload.
  3. Force an early failure (e.g., upload to a bucket without write permissions).
  4. Delete the local file while the process is alive.
  5. Check /proc/<pid>/fd and df/du.

A clear and concise description of what the bug is, and what you expected to happen.

The file descriptor open in bucket.upload remains allocated until the process exists. This causes a small memory leak and prevents the local file from being fully deleted. The relevant code is:

nodejs-storage/src/bucket.ts

Lines 4364 to 4379 in c7004da

fs.createReadStream(pathString)
.on('error', bail)
.pipe(writable)
.on('error', err => {
if (
this.storage.retryOptions.autoRetry &&
this.storage.retryOptions.retryableErrorFn!(err)
) {
return reject(err);
} else {
return bail(err);
}
})
.on('finish', () => {
return resolve();
});

A clear and concise description WHY you expect this behavior, i.e., was it a recent change, there is documentation that points to this behavior, etc. **

The file descriptor should always be closed when the function finishes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    api: storageIssues related to the googleapis/nodejs-storage API.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions