nodegit icon indicating copy to clipboard operation
nodegit copied to clipboard

Getting `Segmentation fault: 11` upon node crash (on regularly basis)

Open DMXL opened this issue 7 years ago • 9 comments

System Info

  • node version: v8.13.0
  • npm or yarn version: v6.4.1
  • OS/version/architecture: macOS 10.14.1
  • Applicable nodegit version: v0.23.0

Description

I went through all related issues closed/open. At first I thought it might be problems with Remote#push, then I found out that commit and stage are also causing node to crash with the same error.

Real trouble is this happens randomly, sometimes after 2 or 3 times of API calling, other times just straight-down crashes on the first call. I even tried to monitor v8 heap/CPU usage, nothing suspicious was found though.

Reinstalling node and node modules didn't work either, but I'm guessing it's still most likely a compatibility issue with node. Any help is appreciated.

Code

The code is posted as follows, in case there is something wrong with the way APIs are called:

const git = require('nodegit')
// ...
const repoInstance = await git.Repository.open(rootPath)
const repoRemote = await repoInstance.getRemote('origin')
const author = git.Signature.now(username, email)
const cred = git.Cred.userpassPlaintextNew(username, password)

const signature = '\nauto commit --ignore'
const commitMessage = `Modify file ${relPath}${signature}`

await repoInstance.stageFilemode(relPath, true)
await repoInstance.createCommitOnHead([relPath], author, author, commitMessage)
return repoRemote.push(['refs/heads/master:refs/heads/master'], {
  callbacks: {
    credentials () {
      return cred
    }
  }
})

DMXL avatar Nov 27 '18 14:11 DMXL

Is this code run in complete isolation or can we expect other things to be running in parallel?

implausible avatar Dec 13 '18 00:12 implausible

This is all the API does. So I guess it depends on the API calls being in parallel or not.

DMXL avatar Dec 13 '18 02:12 DMXL

I am also getting the same error with just the following code

const nodegit = require('nodegit');
nodegit.Repository.open('./').then(function (repo) {
  // Inside of this function we have an open repo
  // console.log(repo);
});

exits with

Segmentation fault: 11

JoyceBabu avatar Apr 21 '19 09:04 JoyceBabu

Can you hook up segfault-handler to your project or a debugger and see where it segfaults?

implausible avatar Apr 22 '19 15:04 implausible

I tried the following code, but it just hangs

var SegfaultHandler = require('segfault-handler');

SegfaultHandler.registerHandler("crash.log");

const nodegit = require('nodegit');
nodegit.Repository.open('./').then(function (repo) {
  // Inside of this function we have an open repo
  // console.log(repo);
});

GDB

(gdb) run test.js
Starting program: /Users/joyce/.nvm/versions/node/v11.7.0/bin/node test.js
[New Thread 0xd03 of process 69559]
During startup program terminated with signal ?, Unknown signal.

LLDB

(lldb) run test.js
Process 69577 launched: '/Users/joyce/.nvm/versions/node/v11.7.0/bin/node' (x86_64)
Process 69577 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x104a80230)
    frame #0: 0x00000001009fba6c node`uv__async_close + 23
node`uv__async_close:
->  0x1009fba6c <+23>: movq   %rcx, 0x8(%rax)
    0x1009fba70 <+27>: movl   0x58(%rdi), %eax
    0x1009fba73 <+30>: testb  $0x4, %al
    0x1009fba75 <+32>: je     0x1009fba8a               ; <+53>
Target 0: (node) stopped.

JoyceBabu avatar Apr 22 '19 16:04 JoyceBabu

the problem looks like to be with return cred it seems we no longer able to reuse the cred object. possible solution could be creating new cred object every time. I solved the issue for me with something like: return Git.Cred.userpassPlaintextNew(getUsername(), getPassword())

Unimax avatar Jun 03 '19 08:06 Unimax

Yes, I can confirm that what Unimax says is correct. In particular, it's because cred objects are owned by libgit2 after they are given to libgit2 through a credentials callback. It's a particularly nasty issue to solve as far as garbage collection and JS object safety goes.

implausible avatar Jun 14 '19 16:06 implausible

Is mine a different issue? Should I create a new GitHub issue?

JoyceBabu avatar Jun 15 '19 13:06 JoyceBabu

Yes, I can confirm that what Unimax says is correct. In particular, it's because cred objects are owned by libgit2 after they are given to libgit2 through a credentials callback. It's a particularly nasty issue to solve as far as garbage collection and JS object safety goes.

Wouldn't it be possible to just have a JS wrapper object, which will create an Cred instance as needed?

lal12 avatar Jan 28 '21 10:01 lal12