Skip to content

Remote.Fetch() - unexpected signal during runtime execution #206

Closed
@radeksimko

Description

@radeksimko

Try running the following snippet of code:

package main

import (
    "fmt"
    "os"
    "path/filepath"

    "github.com/libgit2/git2go"
)

func main() {
    url := "https://github.com/radeksimko/vagrant-osx.git"
    path := filepath.Join(os.TempDir(), "test-git2go")
    cbs := getCallbacks()

    // fmt.Println("Using", path)

    if _, err := os.Stat(path); err == nil {
        repo, err := git.OpenRepository(path)
        if err != nil {
            fmt.Printf("Opening repository failed: %#v\n", err)
        }

        remote, err := repo.LookupRemote("origin")
        if err != nil {
            fmt.Printf("Remote lookup failed: %#v\n", err)
        }

        remote.SetCallbacks(cbs)

        fmt.Println("Fetching remote...")
        err = remote.Fetch([]string{}, nil, "")
        if err != nil {
            fmt.Printf("Fetching remote failed: %#v\n", err)
        }

        fmt.Println("Remotes fetched.")
    } else {
        repo, err := git.Clone(url, path, &git.CloneOptions{
            RemoteCallbacks: cbs,
        })
        if err != nil {
            fmt.Printf("Cloning repo failed: %#v\n", err)
        }

        fmt.Printf("Repo cloned: %#v\n", repo)
    }
}

func getCallbacks() *git.RemoteCallbacks {
    return &git.RemoteCallbacks{
        CredentialsCallback: func(url string, username_from_url string, allowed_types git.CredType) (git.ErrorCode, *git.Cred) {
            ret, cred := git.NewCredUserpassPlaintext("my-username", "**REDACTED**")
            return git.ErrorCode(ret), &cred
        },
    }
}

The commented-out fmt.Println is there intentionally. As it is, it's causing intermittent crashes, e.g.:

$ go run test.go 
Fetching remote...
fatal error: unexpected signal during runtime execution
[signal 0xb code=0x1 addr=0xb01dfacedebac1e pc=0x43b9cb6]

runtime stack:
runtime.gothrow(0x422e5d0, 0x2a)
    /usr/local/Cellar/go/1.4.2/libexec/src/runtime/panic.go:503 +0x8e
runtime.sigpanic()
    /usr/local/Cellar/go/1.4.2/libexec/src/runtime/sigpanic_unix.go:14 +0x5e

goroutine 1 [syscall, locked to thread]:
runtime.cgocall_errno(0x4005410, 0xc208067dd0, 0x0)
    /usr/local/Cellar/go/1.4.2/libexec/src/runtime/cgocall.go:130 +0xf5 fp=0xc208067db0 sp=0xc208067d88
github.com/libgit2/git2go._Cfunc_git_remote_fetch(0x5410470, 0xc208067e18, 0x0, 0x0, 0xc200000000)
    /Users/radeksimko/gopath/src/github.com/libgit2/git2go/:1710 +0x43 fp=0xc208067dd0 sp=0xc208067db0
github.com/libgit2/git2go.(*Remote).Fetch(0xc208054230, 0xc208067e88, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0)
    /Users/radeksimko/gopath/src/github.com/libgit2/git2go/remote.go:628 +0x1ca fp=0xc208067e40 sp=0xc208067dd0
main.main()
    /var/workspace/test/test.go:32 +0x4fd fp=0xc208067f98 sp=0xc208067e40
runtime.main()
    /usr/local/Cellar/go/1.4.2/libexec/src/runtime/proc.go:63 +0xf3 fp=0xc208067fe0 sp=0xc208067f98
runtime.goexit()
    /usr/local/Cellar/go/1.4.2/libexec/src/runtime/asm_amd64.s:2232 +0x1 fp=0xc208067fe8 sp=0xc208067fe0

goroutine 17 [syscall, locked to thread]:
runtime.goexit()
    /usr/local/Cellar/go/1.4.2/libexec/src/runtime/asm_amd64.s:2232 +0x1
exit status 2

but when the fmt.Println is uncommented (= it's printing that one line to stdout), it never crashes:

$ go run test.go 
Using /var/folders/dj/8v7ccb5n3838_mkbkfrxn59jr0_589/T/test-git2go
Fetching remote...
Remotes fetched.

It seems like a memory issue coming from the C code?

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