Revert "Add finalizers to ensure that repos are closed and blobreaders are closed (#19495) (#19496)" (#19659)
This reverts commit 88da50674f
.
because it caused a memleak
This commit is contained in:
parent
0a2d618d85
commit
c7c18e0eb2
3 changed files with 18 additions and 157 deletions
|
@ -12,12 +12,8 @@ import (
|
|||
"context"
|
||||
"errors"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"sync"
|
||||
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
gitealog "code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/process"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
|
||||
"github.com/go-git/go-billy/v5/osfs"
|
||||
|
@ -32,9 +28,6 @@ type Repository struct {
|
|||
|
||||
tagCache *ObjectCache
|
||||
|
||||
lock sync.Mutex
|
||||
closed bool
|
||||
|
||||
gogitRepo *gogit.Repository
|
||||
gogitStorage *filesystem.Storage
|
||||
gpgSettings *GPGSettings
|
||||
|
@ -70,57 +63,23 @@ func OpenRepositoryCtx(ctx context.Context, repoPath string) (*Repository, error
|
|||
return nil, err
|
||||
}
|
||||
|
||||
repo := &Repository{
|
||||
return &Repository{
|
||||
Path: repoPath,
|
||||
gogitRepo: gogitRepo,
|
||||
gogitStorage: storage,
|
||||
tagCache: newObjectCache(),
|
||||
Ctx: ctx,
|
||||
}
|
||||
|
||||
runtime.SetFinalizer(repo, (*Repository).finalizer)
|
||||
|
||||
return repo, nil
|
||||
}, nil
|
||||
}
|
||||
|
||||
// Close this repository, in particular close the underlying gogitStorage if this is not nil
|
||||
func (repo *Repository) Close() (err error) {
|
||||
if repo == nil {
|
||||
func (repo *Repository) Close() {
|
||||
if repo == nil || repo.gogitStorage == nil {
|
||||
return
|
||||
}
|
||||
repo.lock.Lock()
|
||||
defer repo.lock.Unlock()
|
||||
return repo.close()
|
||||
}
|
||||
|
||||
func (repo *Repository) close() (err error) {
|
||||
repo.closed = true
|
||||
if repo.gogitStorage == nil {
|
||||
return
|
||||
}
|
||||
err = repo.gogitStorage.Close()
|
||||
if err != nil {
|
||||
if err := repo.gogitStorage.Close(); err != nil {
|
||||
gitealog.Error("Error closing storage: %v", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (repo *Repository) finalizer() error {
|
||||
if repo == nil {
|
||||
return nil
|
||||
}
|
||||
repo.lock.Lock()
|
||||
defer repo.lock.Unlock()
|
||||
if !repo.closed {
|
||||
pid := ""
|
||||
if repo.Ctx != nil {
|
||||
pid = " from PID: " + string(process.GetPID(repo.Ctx))
|
||||
}
|
||||
log.Error("Finalizer running on unclosed repository%s: %s%s", pid, repo.Path)
|
||||
}
|
||||
|
||||
// We still need to run the close fn as it may be possible to reopen the gogitrepo after close
|
||||
return repo.close()
|
||||
}
|
||||
|
||||
// GoGitRepo gets the go-git repo representation
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue