Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Callback called multiple times, but not always #111

Open
pvencill opened this issue Oct 24, 2016 · 3 comments
Open

Callback called multiple times, but not always #111

pvencill opened this issue Oct 24, 2016 · 3 comments

Comments

@pvencill
Copy link

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.

@jurosh
Copy link

jurosh commented Nov 27, 2016

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);
  });
});

@ericis
Copy link

ericis commented Oct 24, 2017

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();
        });
    }

@ericis
Copy link

ericis commented Oct 24, 2017

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants