Repository navigation
Segmentation Fault #823
Copy link
Copy link
Closed
Description
I'm using NodeGit to setup multiple git repositories.
When I do that I get the error:
[1] 7896 segmentation fault (core dumped) node example.js
This error happens with NodeGit 0.5.0 and 0.6.0.
Running on Ubuntu 15.10, on Node JS 5.2.0 and 4.3.2
Here is the code I am trying to run.
This will work correctly with a single destination, but will SegFault with multiple.
A version of this code previously worked with multiple destinations with NodeGit 0.4.0
'use strict';
const NodeGit = require('nodegit');
const path = require('path');
const temporaryFolder = path.join(__dirname, 'temp');
const branchReference = 'refs/heads/master:refs/heads/master';
// replace this with your own username and password
// seedRepository should have files already
// destinationRepositories should not have any files or commits yet
seedRepositories('testUser', 'password', 'https://github.com/ChristianMurphy/just-a-test-ignore-this', ['https://github.com/ChristianMurphy/please-work-1', 'https://github.com/ChristianMurphy/please-work-2'])
function seedRepositories (username, password, seedRepositoryURL, destinationRepositoryURLs) {
const credentials = NodeGit.Cred.userpassPlaintextNew(username, password);
// clone seed repo
NodeGit.Clone(seedRepositoryURL, temporaryFolder, {
callbacks: {
credentials: function () {
return credentials;
}
}
})
// open the repository
.then(() => {
return NodeGit.Repository.open(temporaryFolder);
})
// push the seed repository to all destination repositories
.then((seedRepository) => {
const promises = [];
// for each destination
for (let index = 0; index < destinationRepositoryURLs.length; index++) {
// create a remote for destination
NodeGit.Remote.create(seedRepository, index.toString(), destinationRepositoryURLs[index]);
// open remote for destination and collect resulting promise
promises.push(
NodeGit.Remote.lookup(seedRepository, index.toString())
.then((remote) => {
// push to destination remote
return remote.push([branchReference], {
callbacks: {
credentials: function () {
return credentials;
}
}
});
})
);
}
// wait for all pushes to complete
return Promise.all(promises);
})
.catch((err) => {
console.error(err);
});
};Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
Activity
ChristianMurphy commentedon Dec 17, 2015
Update.
I tried using promise chaining instead of promise all.
Now instead of
Segmentation FaultIt errors with
*** Error in 'node': double free or corruption (fasttop): 0x0000000001c80ac0 ***Here is the updated code.
tbranyen commentedon Dec 17, 2015
@ChristianMurphy most likely related to this: #827
ChristianMurphy commentedon Dec 17, 2015
Thanks @tbranyen 👍
I'll close this out and follow that thread instead.
ChristianMurphy commentedon Jan 16, 2016
Hey @tbranyen
Quick question, I tried running the above code again in NodeGit 0.8.0
with and without
NodeGit.enableThreadSafety();for some reason
NodeGit.Remote.lookupnow resolves toundefined.Did
NodeGit.Remote.lookupchange in the last release?tbranyen commentedon Jan 16, 2016
No idea wasn't involved in that release, ping @johnhaley81 @maxkorp
johnhaley81 commentedon Jan 16, 2016
I still see that in 0.8.0. Can you reinstall and confirm that it's missing?
ChristianMurphy commentedon Jan 16, 2016
@johnhaley81 the function is there, it is just not finding the remotes.
I reinstalled NodeGit and issue persists.
johnhaley81 commentedon Jan 16, 2016
Oh, I see. I'll check that out when I get back home but we do have automated tests that cover that specific function and they are passing.
ChristianMurphy commentedon Jan 18, 2016
Never mind, I figured it out, there was a race condition between
Remote.createandRemote.lookup.ChristianMurphy commentedon Jan 18, 2016
Well good news and bad news.
Good news it is partially working again. 😄
Bad news back to the same
Segmentation Fault😢This time:
Node 5.4.1
NodeGit 0.8.0
With this demo code.
The code will correctly push to the first repo and seg fault before pushing to the second.
johnhaley81 commentedon Jan 19, 2016
@srajko was something missed in #836 ?
srajko commentedon Jan 19, 2016
I can take a look - @ChristianMurphy thanks for the repro code, I'll give it a try.
#836 is a bit of a "dipping toes in the water" :-) It only enables thread safety for a few types to start with, though I don't necessarily have a great reason for having kept it at only those few types... more of a "I started with those and never added more". So it's possible that adding remotes to the list might help.
srajko commentedon Jan 23, 2016
@ChristianMurphy can you please try to replace
with
For me, this makes the difference between it segfaulting and completing. Does it resolve the problem for you as well?
ChristianMurphy commentedon Jan 24, 2016
That works for me as well 😄
ChristianMurphy commentedon Jan 24, 2016
Thanks @srajko !
srajko commentedon Jan 24, 2016
No problem - thanks for the crash report!
This still needs a deeper look to see what exactly is at fault - so far it looks like the push code might be calling some cred cleanup, and reusing the cred object might not be jiving too well with that.
Possible fix for Segmentation fault based on nodegit/nodegit#823
kachkaev commentedon Jul 23, 2017
Also faced this just now with the latest nodegit. Thanks for your hint @srajko! Originally, I had
credentials: () => credin myremote.pushcall, where cred was defined once in the beginning of the script:This resulted a crash with
[1] 69758 segmentation fault npm startin bash and no exception thrown.After replacing this with
credentials: () => Cred.sshKeyNew(...)crashing stopped! Now thecredobject is being created every time, but at least things work! 🎉