| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Update.
I tried using promise chaining instead of promise all.
Now instead of Segmentation Fault
It errors with *** Error in 'node': double free or corruption (fasttop): 0x0000000001c80ac0 ***
Here is the updated code.
'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 chain = Promise.resolve();
// for each destination
for (let index = 0; index < destinationRepositoryURLs.length; index += 1) {
// create a remote for destination
NodeGit.Remote.create(seedRepository, index.toString(), destinationRepositoryURLs[index]);
// open remote for destination
chain.then(
NodeGit.Remote.lookup(seedRepository, index.toString())
);
// push to the remote
chain.then((remote) => {
// push to destination remote
return remote.push([branchReference], {
callbacks: {
credentials () {
return credentials;
}
}
});
});
}
// wait for all pushes to complete
return chain;
})
.catch((err) => {
console.error(err);
});
};@ChristianMurphy most likely related to this: #827
Thanks @tbranyen 👍
I'll close this out and follow that thread instead.
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.lookup now resolves to undefined.
Did NodeGit.Remote.lookup change in the last release?
No idea wasn't involved in that release, ping @johnhaley81 @maxkorp
I still see that in 0.8.0. Can you reinstall and confirm that it's missing?
@johnhaley81 the function is there, it is just not finding the remotes.
I reinstalled NodeGit and issue persists.
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.
Never mind, I figured it out, there was a race condition between Remote.create and Remote.lookup.
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.
'use strict';
const NodeGit = require('nodegit');
const path = require('path');
const temporaryFolder = path.join(__dirname, 'temp');
const branchReference = 'refs/heads/master:refs/heads/master';
NodeGit.enableThreadSafety();
// 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) => {
let chain = Promise.resolve();
// for each destination
for (let index = 0; index < destinationRepositoryURLs.length; index += 1) {
// open remote for destination
chain = chain
.then(() => {
return NodeGit.Remote.create(seedRepository, index.toString(), destinationRepositoryURLs[index]);
})
.then((remote) => {
// push to destination remote
return remote.push([branchReference], {
callbacks: {
credentials () {
return credentials;
}
}
});
});
}
// wait for all pushes to complete
return chain;
})
.catch((err) => {
console.error(err);
});
};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.
@ChristianMurphy can you please try to replace
return remote.push([branchReference], {
callbacks: {
credentials () {
return credentials;
}
}
});
with
return remote.push([branchReference], {
callbacks: {
credentials () {
return NodeGit.Cred.userpassPlaintextNew(username, password);
}
}
});
For me, this makes the difference between it segfaulting and completing. Does it resolve the problem for you as well?
That works for me as well 😄
Thanks @srajko !
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.
Also faced this just now with the latest nodegit. Thanks for your hint @srajko! Originally, I had credentials: () => cred in my remote.push call, where cred was defined once in the beginning of the script:
const cred = Cred.sshKeyNew('git', pathPoPublicKey, pathToPrivateKey, '');This resulted a crash with [1] 69758 segmentation fault npm start in bash and no exception thrown.
After replacing this with credentials: () => Cred.sshKeyNew(...) crashing stopped! Now the cred object is being created every time, but at least things work! 🎉
| Back | FazBrowse Home | New Git URL |
I'm using NodeGit to setup multiple git repositories.
When I do that I get the error:
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