Skip to content
This repository was archived by the owner on Dec 2, 2026. It is now read-only.
This repository was archived by the owner on Dec 2, 2026. It is now read-only.

nodegit doesn't return control to the calling application #497

Closed

Description

@dancrumb

I have the following code

var cloneOptions = {};
cloneOptions.remoteCallbacks = {
    credentials: function(url, userName) {
        return NodeGit.Cred.sshKeyFromAgent(userName);
    }
};
logger.info('Cloning snapshot repo');
var getMostRecentCommit = function(repository) {
    return repository.getBranchCommit('master');
};

var getCommitMessage = function(commit) {
    return commit.message();
};
NodeGit.Clone(remoteRepo, path.join('_deployments',deployFolderName), cloneOptions )
    .then(getMostRecentCommit, function() { logger.error('error %o', arguments);})
    .then(getCommitMessage, function() { logger.error('error %o', arguments);})
    .then(function(message) {
        return logger.info(message);
    }, function() { logger.error('error %o', arguments);});

This is largely copypasta from your site.

The NodeGit.* chain is working fine; the repo is being cloned and I'm getting the right commit message.

However, my application then just sits and waits. There's no indication in the nodegit docs that I need to manually resolve the Promise or anything like in order for my application to complete.

What am I missing here? Or is this a nodegit bug?

Activity

  1. tbranyen commented on Mar 19, 2015

    @tbranyen
    Member

    How is it being used? Run that code in a single file and it'll exit just fine. Is your application hanging, because it's a server or something?

  2. johnhaley81 commented on Mar 19, 2015

    @johnhaley81
    Collaborator

    How large is your repository? Have you set up any progress callbacks?

  3. dancrumb commented on Mar 19, 2015

    @dancrumb
    Author

    @johnhaley81 the repo isn't that large and it's progressing fine (I added the callback to confirm).

    The commit message is being reported, so we're getting that far. It's just that the application isn't closing.

  4. dancrumb commented on Mar 19, 2015

    @dancrumb
    Author

    @tbranyen it's a CLI app and, when I remove the NodeGit chain, it completes without any problems.

  5. tbranyen commented on Mar 19, 2015

    @tbranyen
    Member

    @dancrumb can you confirm if you run that code standalone on the CLI it exits?

  6. johnhaley81 commented on Mar 19, 2015

    @johnhaley81
    Collaborator

    @dancrumb can you add a .done on the end of the chain?

  7. dancrumb commented on Mar 19, 2015

    @dancrumb
    Author

    I ran the script at https://gist.github.com/dancrumb/1b437d2d1da8b88ea62b and got the output:

    $ node test.js                                                                                                                                                                                                  
    [DEBUG]: Remote stash repo: ssh://git@stash.vodori.com:2121/ps/pepper-demo-site.git
    [DEBUG]: Cloning into _deployments/test
    [INFO]: Cloning snapshot repo
    [INFO]: v3.12.3
    
    [INFO]: Donezo
    

    where it just waits

  8. tbranyen commented on Mar 19, 2015

    @tbranyen
    Member

    @dancrumb unfortunately that test case uses a logging tool that could be causing a problem:

    here is a reduced test case I used that worked perfectly:

    var path    =  require('path');
    var NodeGit = require('./nodegit');
    
    // create tmp folder
    var deployFolderName = 'test';
    
    // clone into tmp folder
    var remoteRepo = 'git@github.com:nodegit/test';
    var cloneOptions = {};
    cloneOptions.remoteCallbacks = {
        credentials: function(url, userName) {
            return NodeGit.Cred.sshKeyFromAgent(userName);
        },
        transferProgress: function(info) {
          return console.log(info);
        }
    };
    var getMostRecentCommit = function(repository) {
        return repository.getBranchCommit('master');
    };
    
    var getCommitMessage = function(commit) {
        return commit.message();
    };
    NodeGit.Clone(remoteRepo, path.join('_deployments',deployFolderName), cloneOptions )
        .then(getMostRecentCommit, function() { console.log('error %o', arguments);})
        .then(getCommitMessage, function() { console.log('error %o', arguments);})
        .then(function(message) {
            return console.log(message);
        }, function() { console.log('error %o', arguments);})
        .done(function() {
            console.log('Donezo');
        });
  9. tbranyen commented on Mar 19, 2015

    @tbranyen
    Member

    Whoops, sorry about that, absentmindedly clicked the close button.

  10. dancrumb commented on Mar 19, 2015

    @dancrumb
    Author

    I ran

    var path    =  require('path');
    var NodeGit = require('nodegit');
    
    // create tmp folder
    var deployFolderName = 'test';
    
    // clone into tmp folder
    var remoteRepo = 'ssh://git@stash.vodori.com:2121/ps/pepper-demo-site.git';
    console.log('Remote stash repo: %s', remoteRepo);
    console.log('Cloning into %s', path.join('_deployments',deployFolderName));
    var cloneOptions = {};
    cloneOptions.remoteCallbacks = {
        credentials: function(url, userName) {
            return NodeGit.Cred.sshKeyFromAgent(userName);
        }
    };
    console.log('Cloning snapshot repo');
    var getMostRecentCommit = function(repository) {
        return repository.getBranchCommit('master');
    };
    
    var getCommitMessage = function(commit) {
        return commit.message();
    };
    NodeGit.Clone(remoteRepo, path.join('_deployments',deployFolderName), cloneOptions )
        .then(getMostRecentCommit, function() { console.log('error %o', arguments);})
        .then(getCommitMessage, function() {console.log('error %o', arguments);})
        .then(function(message) {
            return console.log(message);
        }, function() { console.log('error %o', arguments);})
        .done(function() {
            console.log('Donezo');
        });

    and see the same behaviour.

    I'm on Mint Linux, in a zshell on node 0.10.33

    What are you on?

  11. dancrumb commented on Mar 19, 2015

    @dancrumb
    Author

    I also checked with git@github.com:nodegit/test... same problem (which is what I expected, but figured was worth checking)

  12. dancrumb commented on Mar 19, 2015

    @dancrumb
    Author

    Also seen on a Mac, zshell, node 0.11.14

  13. johnhaley81 commented on Mar 19, 2015

    @johnhaley81
    Collaborator

    I'm getting the same behavior as @dancrumb. It just hangs. Looking into it more.

  14. 11 remaining items

  15. JediMindtrick commented on Mar 22, 2015

    @JediMindtrick

    In the case of this happening in the context of a long-running process (i.e. express server) do you think the hang would be a problem? A little concerned that maybe it's hanging onto some kind of open connection and that over time this might cause problems...

  16. tbranyen commented on Mar 22, 2015

    @tbranyen
    Member

    @JediMindtrick I seriously doubt it's hanging on to any kind of connection, @johnhaley81 is usually right about his hunches: #497 (comment)

  17. johnhaley81 commented on Mar 23, 2015

    @johnhaley81
    Collaborator

    @tbranyen well I've definitely been wrong before :)

    @JediMindtrick if you want to try it out write a quick script that uses callback functions in the processing of a call that does open any connections. Nodegit.Status.foreach would do the trick. It should still hang after your script is finished processing.

    I'm definitely looking into this more but at least we have a sort of work-around for right now.

  18. added a commit that references this issue on Apr 20, 2015
    c377722
  19. johnhaley81 commented on Apr 20, 2015

    @johnhaley81
    Collaborator

    The handles that were created for callback's being executed on the main thread needed to be cleaned up via uv_close. That's about to get merged into master which should fix this.

  20. juanbrujo commented on Apr 22, 2015

    @juanbrujo

    @johnhaley81 suggestion #497 (comment) definetly worked

  21. johnhaley81 commented on Apr 22, 2015

    @johnhaley81
    Collaborator

    @juanbrujo this will be fixed in the next release FYI.

  22. JediMindtrick commented on Apr 22, 2015

    @JediMindtrick

    @johnhaley81 Thanks for fixing this.

  23. kevindashgit commented on Mar 26, 2016

    @kevindashgit

    In the meantime, you could put process.exit() in the .done method.

    I don't see how this helps? I don't ever get to the done part of the promise chain. What am I missing?

  24. dancrumb commented on Mar 26, 2016

    @dancrumb
    Author

    You're probably better off open up a new issue with your failing choice

  25. tbranyen commented on Mar 26, 2016

    @tbranyen
    Member

    Also, @kevindashgit you offered no additional information necessary for us to assist you. Can you provide OS, Node version, NodeGit version, prebuilt or built from source, and the script that is failing?

    No need to open a new issue, but if you want more rapid help, drop into our Gitter

  26. kevindashgit commented on Mar 28, 2016

    @kevindashgit

    More Info:

    OS: OSX El Capitan v10.11.1
    Node Version: 1.2.0.10
    NodeGit Version: ^0.11.9 (prebuilt)
    Script:

    cloneOptions.fetchOpts = {
          callbacks: {
            certificateCheck: function() { return 1; },
            credentials: function(GITLAB_URL, userName) {
              console.log('help im stuck in an infinite loop');
              return NodeGit.Cred.sshKeyFromAgent(userName);
            },
            transferProgress: function(info) {
              return console.log(info);
            }
          }
        };
    
        var getMostRecentCommit = function(repository) {
            return repository.getBranchCommit('master');
        };
    
        var getCommitMessage = function(commit) {
            return commit.message();
        };
        NodeGit.Clone(siteUrl, path.join(__dirname, 'sites', test.name), cloneOptions)
            .then(getMostRecentCommit, function() { console.log('error %o', arguments);})
            .then(getCommitMessage, function() { console.log('error %o', arguments);})
            .then(function(message) {
                return console.log(message);
            }, function() { console.log('error %o', arguments);})
            .done(function() {
                console.log('Donezo');
                process.exit();
            });
    
  27. tbranyen commented on Mar 28, 2016

    @tbranyen
    Member

    Thanks so much for updating us with some more information, I'm probably not the best one to diagnose, but I'll try and reproduce locally to at least verify.

    Ping @johnhaley81 who can assist, or know who best to assist.

  28. johnhaley81 commented on Mar 29, 2016

    @johnhaley81
    Collaborator

    @kevindashgit you're giving back wrong credentials and NodeGit will ask you for creds until you either pass back one that works or pass back NodeGit.Cred.defaultNew()

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions