You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Dec 2, 2026. It is now read-only.
Repository navigation
This repository was archived by the owner on Dec 2, 2026. It is now read-only.
'use strict';varpath=require('path');varGit=require('nodegit');varfetchOpts={callbacks: {certificateCheck: function(){return1;},credentials: function(url,userName){returnGit.Cred.sshKeyNew('git',path.resolve('/Users/holblin/.ssh/id_rsa.pub'),path.resolve('/Users/holblin/.ssh/id_rsa'),'');}}};Promise.resolve().then(function(){varall=[];for(vari=0;i<2;i++){all.push(updateIt('repo_'+i));}returnPromise.all(all);})functionupdateIt(i){varrepository,localHeadCommit;vardir='tests/'+i;returnGit.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.
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.
After some try, I still have similar issues.
My new code is:
'use strict';varpath=require('path');varGit=require('nodegit');functionfetchOpts(){return{callbacks: {certificateCheck: function(){return1;},credentials: function(url,userName){returnGit.Cred.sshKeyNew('git',path.resolve('/Users/holblin/.ssh/id_rsa.pub'),path.resolve('/Users/holblin/.ssh/id_rsa'),'');}}};}Promise.resolve().then(function(){varall=[];for(vari=0;i<2;i++){all.push(updateIt('repo_'+i));}returnPromise.all(all);})functionupdateIt(i){varrepository,localHeadCommit;vardir='tests/'+i;returnGit.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'))}
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).
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.
Activity
johnhaley81 commentedon Feb 17, 2016
You'll need to create a new
fetchOptsfor 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.holblin commentedon Feb 17, 2016
After some try, I still have similar issues.
My new code is:
Still have the same results.
holblin commentedon Feb 17, 2016
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:
johnhaley81 commentedon Feb 18, 2016
/cc @srajko
srajko commentedon Feb 18, 2016
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!
johnhaley81 commentedon Feb 22, 2016
@holblin can you try to test this with 0.11.3?
holblin commentedon Feb 23, 2016
@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 ;-)