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.

Malloc bug with fetchAll and ssh. #907

Closed

Description

@holblin

Hi,

I have a bug with fetchAll action.

I make this simple code for testing this bugs:

'use strict';
var path = require('path');
var Git = require('nodegit');

var fetchOpts = {
  callbacks: {
    certificateCheck: function() { return 1; },
    credentials: function(url, userName) {
      return Git.Cred.sshKeyNew('git', path.resolve('/Users/holblin/.ssh/id_rsa.pub'), path.resolve('/Users/holblin/.ssh/id_rsa'), '');
    }
  }
};

Promise.resolve()
.then(function() {
  var all =[];
  for (var i = 0; i < 2; i++) {
    all.push(updateIt('repo_'+i));
  }
  return Promise.all(all);
})

function updateIt(i) {
  var repository, localHeadCommit;
  var dir = 'tests/'+i;

  return Git.Repository.open(dir)
    .then((repo) => repository = repo) // save the reference for futur use
    .then(() => console.log('['+i+'] openRepo'))
    .then(() => repository.fetchAll(fetchOpts)) // fetch all data from all remotes
    .then(() => console.log('['+i+'] fetchAll'))
}

For use it, make this commands first:

npm -i path nodegit
mkdir tests
cd tests
git clone git@<repository1_git_url>.git repo_0
git clone git@<repository2_git_url>.git repo_1
cd ..

I have a Mac os, X yosemite version 10.10.5. I use nvm with node v5.5.0.
My uname -a is Darwin zolesio 14.5.0 Darwin Kernel Version 14.5.0: Tue Sep 1 21:23:09 PDT 2015; root:xnu-2782.50.1~1/RELEASE_X86_64 x86_64.
The nodegit version is: nodegit@0.11.1

Sometimes, it finished with:

[repo_0] openRepo
[repo_1] openRepo
node(5166,0x1026cd000) malloc: *** error for object 0x102303d00: pointer being realloc'd was not allocated
*** set a breakpoint in malloc_error_break to debug
Abort trap: 6

Sometimes with:

[repo_0] openRepo
[repo_1] openRepo
node(5058,0x105087000) malloc: *** error for object 0x10170e960: double free
*** set a breakpoint in malloc_error_break to debug
Abort trap: 6

Sometimes with:

[repo_0] openRepo
[repo_1] openRepo
Bus error: 10

Sometimes with getting stuck and use 200% of my CPU.

Activity

  1. johnhaley81 commented on Feb 17, 2016

    @johnhaley81
    Collaborator

    You'll need to create a new fetchOpts for each call. Internally in C++ those opts will be freed after the call is completed which will result in a segfault if they are used in other parts of the app.

  2. holblin commented on Feb 17, 2016

    @holblin
    Author

    After some try, I still have similar issues.
    My new code is:

    'use strict';
    var path = require('path');
    var Git = require('nodegit');
    
    function fetchOpts(){
      return {
        callbacks: {
          certificateCheck: function() { return 1; },
          credentials: function(url, userName) {
            return Git.Cred.sshKeyNew('git', path.resolve('/Users/holblin/.ssh/id_rsa.pub'), path.resolve('/Users/holblin/.ssh/id_rsa'), '');
          }
        }
      };
    }
    
    Promise.resolve()
    .then(function() {
      var all =[];
      for (var i = 0; i < 2; i++) {
        all.push(updateIt('repo_'+i));
      }
      return Promise.all(all);
    })
    
    function updateIt(i) {
      var repository, localHeadCommit;
      var dir = 'tests/'+i;
    
      return Git.Repository.open(dir)
        .then((repo) => repository = repo) // save the reference for futur use
        .then(() => console.log('['+i+'] openRepo'))
        .then(() => repository.fetchAll(fetchOpts())) // fetch all data from all remotes
        .then(() => console.log('['+i+'] fetchAll'))
    }

    Still have the same results.

  3. holblin commented on Feb 17, 2016

    @holblin
    Author

    After discussion with you directly on gitter I use the .enableThreadSafety(); feature.
    This reduce a lot the errors but I still have errors (like 1/10 with my experimental testing).

    Changements in my previous code:

    var Git = require('nodegit');
    Git.enableThreadSafety();
  4. johnhaley81 commented on Feb 18, 2016

    @johnhaley81
    Collaborator
  5. srajko commented on Feb 18, 2016

    @srajko
    Collaborator

    Oh boy. I experimented with this a bit and it looks like our locking strategy might be insufficient - the bulk of what we were going for was making sure that no two libgit2 calls run concurrently on the same repository. But this example demonstrates that concurrent fetches on separate repositories are also susceptible to crashing.

    As a test, I modified the thread safety code to completely prevent concurrent access to libgit2, and that does seem to prevent the crashes. So we may need to rethink our thread safety strategy.

    Thanks for submitting this @holblin!

  6. johnhaley81 commented on Feb 22, 2016

    @johnhaley81
    Collaborator

    @holblin can you try to test this with 0.11.3?

  7. holblin commented on Feb 23, 2016

    @holblin
    Author

    @johnhaley81 Yes it works !
    I also remove Git.enableThreadSafety(); from my code and it's works too !

    Thanks to the team for big reactivity and take care of my case ;-)

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions