Skip to content

memory leak with clone #315

Open
Open
@axetroy

Description

@axetroy

When I cloned a repo about 1G in size, it consumed my 1G of memory and generated a lot of stacks

// 拉取代码
func (p *Puller) Pull() (string, error) {
	p.logger.Printf("Pulling %s\n", p.repo)

	options := git.CloneOptions{
		URL:               p.repo,
		Progress:          p.writer,
		SingleBranch:      true,
		ReferenceName:     plumbing.ReferenceName("refs/heads/dev"),
		Depth:             1,
		RecurseSubmodules: git.DefaultSubmoduleRecursionDepth,
	}

	if p.auth != nil {
		options.Auth = *p.auth
	}

	tempDir := os.TempDir()

	rootPath := filepath.Join(tempDir, p.taskID)

	p.logger.Printf("拉取项目到目录 %s\n", rootPath)

	// clone project
	fs := osfs.New(rootPath)

	gitDir := filepath.Join(rootPath, ".git")

	storage := filesystem.NewStorage(osfs.New(gitDir), cache.NewObjectLRU(cache.MiByte*50))

	_, err := git.CloneContext(p.ctx, storage, fs, &options)

	if err != nil {
		return "", errors.WithStack(err)
	}

	return rootPath, nil
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions