Skip to content

copyFile can fail with EMFILE #208

@mbargiel

Description

@mbargiel

The copyFile wrapper implemented in #199 has a small flaw. Unlike the other wrappers, the enqueue function of copyFile https://github.com/isaacs/node-graceful-fs/pull/199/files#diff-05bab169a94002226e0f82bf51c510b4fd2c6cd53f5d558c1ea4136c24a0d7c8R177-R179 enqueues the wrapped function (fs$copyFile) rather than the wrapper which implements the enqueue + retry logic (go$copyFile).

I hit the following issue on v4.2.6. An EMFILE error occurred on a copyFile; then on the retry attempt, another EMFILE error occurred, but that one bubbled up.

The copyFile function needs to be slightly modified to follow the same pattern as the other functions.

I can try to open a PR soon, but basically the following snippet (https://github.com/isaacs/node-graceful-fs/pull/199/files#diff-05bab169a94002226e0f82bf51c510b4fd2c6cd53f5d558c1ea4136c24a0d7c8R177-R179) needs to be changed:

    return fs$copyFile(src, dest, function (err) {
      if (err && (err.code === 'EMFILE' || err.code === 'ENFILE'))
        enqueue([fs$copyFile, [src, dest, cb]])

should be

    return go$copyFile(src, dest, cb)
    
    function go$copyFile(src, dest, cb) {
      return fs$copyFile(src, dest, function (err) {
        if (err && (err.code === 'EMFILE' || err.code === 'ENFILE'))
          enqueue([go$copyFile, [src, dest, cb]])

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions