Skip to content

Commit 41fcf7b

Browse files
zeripath6543
andauthored
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 <[email protected]> Co-authored-by: 6543 <[email protected]>
1 parent 3fbaa79 commit 41fcf7b

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

modules/indexer/code/indexer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ func Init() {
133133
finished()
134134
})
135135

136-
waitChannel := make(chan time.Duration)
136+
waitChannel := make(chan time.Duration, 1)
137137

138138
// Create the Queue
139139
switch setting.Indexer.RepoType {

modules/indexer/issues/indexer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ var (
104104
func InitIssueIndexer(syncReindex bool) {
105105
ctx, _, finished := process.GetManager().AddTypedContext(context.Background(), "Service: IssueIndexer", process.SystemProcessType, false)
106106

107-
waitChannel := make(chan time.Duration)
107+
waitChannel := make(chan time.Duration, 1)
108108

109109
// Create the Queue
110110
switch setting.Indexer.IssueType {

services/repository/archiver/archiver.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ func doArchive(r *ArchiveRequest) (*repo_model.RepoArchiver, error) {
172172
w.Close()
173173
rd.Close()
174174
}()
175-
done := make(chan error)
175+
done := make(chan error, 1) // Ensure that there is some capacity which will ensure that the goroutine below can always finish
176176
repo, err := repo_model.GetRepositoryByID(archiver.RepoID)
177177
if err != nil {
178178
return nil, fmt.Errorf("archiver.LoadRepo failed: %v", err)

0 commit comments

Comments
 (0)