Segfault when calling index.AddAll #917

Open
opened 2022-07-12 10:37:07 -05:00 by pjbgf · 0 comments
pjbgf commented 2022-07-12 10:37:07 -05:00 (Migrated from github.com)

We have experienced index.AddAll causing segfaults. The exact same code depending on the machine it is running on and the repository it is adding files to, may consistently result in a segfault from a background thread:
signal: segmentation fault (core dumped).

In other cases, it may not happen as consistently or not happen at all.
The code extract below is what led to the segfault:

	var parentC []*libgit2.Commit
	head, err := headCommit(repo)
	if err == nil {
		defer head.Free()
		parentC = append(parentC, head)
	}

	index, err := repo.Index()
	if err != nil {
		return "", err
	}
	defer index.Free()

	tracelog.Info("adding files to index")
	c := 1
	err = index.AddAll(nil, libgit2.IndexAddDefault, func(s1, s2 string) error {
		tracelog.Info("adding file", "name", s1, "count", c)
		c += 1
		return nil
	})
	if err != nil {
		return "", err
	}
	tracelog.Info("added files to index")

235edabafd/controllers/imageupdateautomation_controller.go (L627)

Versions:

  • github.com/libgit2/git2go/v33 v33.0.9
  • libgit2 v1.3.1

Relates to https://github.com/fluxcd/image-automation-controller/issues/339

We have experienced `index.AddAll` causing segfaults. The exact same code depending on the machine it is running on **and** the repository it is adding files to, may consistently result in a `segfault` from a background thread: `signal: segmentation fault (core dumped)`. In other cases, it may not happen as consistently or not happen at all. The code extract below is what led to the segfault: ```golang var parentC []*libgit2.Commit head, err := headCommit(repo) if err == nil { defer head.Free() parentC = append(parentC, head) } index, err := repo.Index() if err != nil { return "", err } defer index.Free() tracelog.Info("adding files to index") c := 1 err = index.AddAll(nil, libgit2.IndexAddDefault, func(s1, s2 string) error { tracelog.Info("adding file", "name", s1, "count", c) c += 1 return nil }) if err != nil { return "", err } tracelog.Info("added files to index") ``` https://github.com/fluxcd/image-automation-controller/blob/235edabafd1ce34c15635d6c6b5aea18d298a4d3/controllers/imageupdateautomation_controller.go#L627 Versions: - `github.com/libgit2/git2go/v33 v33.0.9` - `libgit2 v1.3.1` Relates to https://github.com/fluxcd/image-automation-controller/issues/339
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: jcarr/git2go#917
No description provided.