8000 Callback called multiple times, but not always · Issue #111 · AvianFlu/ncp · GitHub
[go: up one dir, main page]

Skip to content

Callback called multiple times, but not always #111

Open

Description

@pvencill

Not sure how to replicate; I am running a test for another project where I'm using ncp to duplicate a file directory (so the original sample isn't modified for the test). I am getting an error on some (but not all) of my tests that "Done is being called multiple times", and I can verify that behavior by passing my own function in the callback and logging every time it's called. It appears to be just happening on one of the project directories that I'm copying.

In any case, there's no instance ever that a callback should be called more than once, so this is a bug.

Activity

  1. jurosh commented on Nov 27, 2016

    @jurosh

    I also noticed strange behavior...
    seems like longer copy tasks callbacks get called more times (instead of faster copy actions) BUT only when I run it for second time - so that files already exists.

    Look at the results, numbers are assigned before staring any copy actions:

    C:\bin\commands\backup\backuper>node index.js
    STARTED 1||hosts
    STARTED 2||.dotvm
    STARTED 3||.homestead
    STARTED 4||.ssh
    STARTED 5||.vagrant.d
    STARTED 6||.VirtualBox
    STARTED 7||Desktop
    STARTED 8||Scanned Documents
    STARTED 9||Downloads
    STARTED 10||Pictures
    STARTED 11||Videos
    STARTED 12||.gitconfig
    FINISHED 1||hosts
    FINISHED 12||.gitconfig
    FINISHED 11||Videos
    FINISHED 8||Scanned Documents
    FINISHED 7||Desktop
    FINISHED 6||.VirtualBox
    FINISHED 4||.ssh
    FINISHED 2||.dotvm
    FINISHED 3||.homestead
    FINISHED 9||Downloads
    FINISHED 10||Pictures
    FINISHED 5||.vagrant.d
    
    C:\bin\commands\backup\backuper>node index.js
    STARTED 1||hosts
    STARTED 2||.dotvm
    STARTED 3||.homestead
    STARTED 4||.ssh
    STARTED 5||.vagrant.d
    STARTED 6||.VirtualBox
    STARTED 7||Desktop
    STARTED 8||Scanned Documents
    STARTED 9||Downloads
    STARTED 10||Pictures
    STARTED 11||Videos
    STARTED 12||.gitconfig
    FINISHED 1||hosts
    FINISHED 12||.gitconfig
    FINISHED 8||Scanned Documents
    FINISHED 9||Downloads
    FINISHED 11||Videos
    FINISHED 3||.homestead
    FINISHED 2||.dotvm
    FINISHED 5||.vagrant.d
    FINISHED 5||.vagrant.d
    FINISHED 5||.vagrant.d
    FINISHED 5||.vagrant.d
    FINISHED 5||.vagrant.d
    FINISHED 5||.vagrant.d
    

    And ugly debug code:

    var count = 0;
    config(cm).srcs.forEach(function(src) {
      count ++;
      const srcc = count + '||' + src.split('\\')[src.split('\\').length - 1];
      console.log('STARTED', srcc);
      const target = '_backup\\' + src.replace(cm.SYSTEM_DRIVE + '\\', '');
      const targetDir = target.split(path.sep).slice(0, -1).join(path.sep);
      prepareDirSync(targetDir);
      ncp(src, target, function (err) {
        console.log('FINISHED', srcc);
      });
    });
    
  2. ericis commented on Oct 24, 2017

    @ericis

    Same issue. Outstanding for a year?

    no instance ever that a callback should be called more than once

    The Typescript code below ends up logging [DefaultFileReader] copyDirectoryTree() only once, but [DefaultFileReader] ncp callback is logged 5 times.

        copyDirectoryTree(sourceDirectory: string, destinationDirectory: string, callback: () => void, errCallback: (err: NodeJS.ErrnoException) => void) {
            console.log('[DefaultFileReader] copyDirectoryTree()');
    
            ncp.limit = 16;
    
            ncp(sourceDirectory, destinationDirectory, err => {
                console.log('[DefaultFileReader] ncp callback');
                if (err) {
                    errCallback(err);
                    return;
                }
    
                callback();
            });
        }
    
  3. ericis commented on Oct 24, 2017

    @ericis

    Switching to fs-extra copy command worked for me.

    https://github.com/jprichardson/node-fs-extra/blob/HEAD/docs/copy.md

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

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

      0