1
0
Fork 0

Prevent dangling archiver goroutine (#19516)

Within doArchive there is a service goroutine that performs the
archiving function.  This goroutine reports its error using a `chan
error` called `done`. Prior to this PR this channel had 0 capacity
meaning that the goroutine would block until the `done` channel was
cleared - however there are a couple of ways in which this channel might
not be read.

The simplest solution is to add a single space of capacity to the
goroutine which will mean that the goroutine will always complete and
even if the `done` channel is not read it will be simply garbage
collected away.

(The PR also contains two other places when setting up the indexers
which do not leak but where the blocking of the sending goroutine is
also unnecessary and so we should just add a small amount of capacity
and let the sending goroutine complete as soon as it can.)

Signed-off-by: Andrew Thornton <art27@cantab.net>

Co-authored-by: 6543 <6543@obermui.de>
This commit is contained in:
zeripath 2022-04-27 00:22:26 +01:00 committed by GitHub
parent 3fbaa79c6e
commit 41fcf7b7de
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 3 additions and 3 deletions

View file

@ -133,7 +133,7 @@ func Init() {
finished() finished()
}) })
waitChannel := make(chan time.Duration) waitChannel := make(chan time.Duration, 1)
// Create the Queue // Create the Queue
switch setting.Indexer.RepoType { switch setting.Indexer.RepoType {

View file

@ -104,7 +104,7 @@ var (
func InitIssueIndexer(syncReindex bool) { func InitIssueIndexer(syncReindex bool) {
ctx, _, finished := process.GetManager().AddTypedContext(context.Background(), "Service: IssueIndexer", process.SystemProcessType, false) ctx, _, finished := process.GetManager().AddTypedContext(context.Background(), "Service: IssueIndexer", process.SystemProcessType, false)
waitChannel := make(chan time.Duration) waitChannel := make(chan time.Duration, 1)
// Create the Queue // Create the Queue
switch setting.Indexer.IssueType { switch setting.Indexer.IssueType {

View file

@ -172,7 +172,7 @@ func doArchive(r *ArchiveRequest) (*repo_model.RepoArchiver, error) {
w.Close() w.Close()
rd.Close() rd.Close()
}() }()
done := make(chan error) done := make(chan error, 1) // Ensure that there is some capacity which will ensure that the goroutine below can always finish
repo, err := repo_model.GetRepositoryByID(archiver.RepoID) repo, err := repo_model.GetRepositoryByID(archiver.RepoID)
if err != nil { if err != nil {
return nil, fmt.Errorf("archiver.LoadRepo failed: %v", err) return nil, fmt.Errorf("archiver.LoadRepo failed: %v", err)