FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Segmentation Fault · Issue #823 · nodegit/nodegit · GitHub

Repository navigation

Segmentation Fault #823

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);
    });
};

Activity

  1. ChristianMurphy commented on Dec 17, 2015

    Author

    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);
        });
    };
  2. tbranyen commented on Dec 17, 2015

    Member

    @ChristianMurphy most likely related to this: #827

  3. ChristianMurphy commented on Dec 17, 2015

    Author

    Thanks @tbranyen 👍
    I'll close this out and follow that thread instead.

  4. ChristianMurphy commented on Jan 16, 2016

    Author

    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?

  5. tbranyen commented on Jan 16, 2016

    Member

    No idea wasn't involved in that release, ping @johnhaley81 @maxkorp

  6. johnhaley81 commented on Jan 16, 2016

    Collaborator

    I still see that in 0.8.0. Can you reinstall and confirm that it's missing?

  7. ChristianMurphy commented on Jan 16, 2016

    Author

    @johnhaley81 the function is there, it is just not finding the remotes.
    I reinstalled NodeGit and issue persists.

  8. johnhaley81 commented on Jan 16, 2016

    Collaborator

    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.

  9. ChristianMurphy commented on Jan 18, 2016

    Author

    Never mind, I figured it out, there was a race condition between Remote.create and Remote.lookup.

  10. ChristianMurphy commented on Jan 18, 2016

    Author

    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);
        });
    };
  11. johnhaley81 commented on Jan 19, 2016

    Collaborator

    @srajko was something missed in #836 ?

  12. srajko commented on Jan 19, 2016

    Collaborator

    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.

  13. srajko commented on Jan 23, 2016

    Collaborator

    @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?

  14. ChristianMurphy commented on Jan 24, 2016

    Author

    That works for me as well 😄

  15. ChristianMurphy commented on Jan 24, 2016

    Author

    Thanks @srajko !

  16. srajko commented on Jan 24, 2016

    Collaborator

    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.

  17. kachkaev commented on Jul 23, 2017

    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! 🎉

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


      Back | FazBrowse Home | New Git URL