Getting `Segmentation fault: 11` upon node crash (on regularly basis)
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
}
}
})
Is this code run in complete isolation or can we expect other things to be running in parallel?
This is all the API does. So I guess it depends on the API calls being in parallel or not.
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
Can you hook up segfault-handler to your project or a debugger and see where it segfaults?
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.
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())
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.
Is mine a different issue? Should I create a new GitHub issue?
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?