Skip to content

Commit 39a0db6

Browse files
zeripath6543
andauthored
Prevent dangling archiver goroutine (#19516) (#19526)
Backport #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]> Co-authored-by: 6543 <[email protected]>
1 parent 9cc93c0 commit 39a0db6

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
@@ -130,7 +130,7 @@ func Init() {
130130
log.Info("PID: %d Repository Indexer closed", os.Getpid())
131131
})
132132

133-
waitChannel := make(chan time.Duration)
133+
waitChannel := make(chan time.Duration, 1)
134134

135135
// Create the Queue
136136
switch setting.Indexer.RepoType {

modules/indexer/issues/indexer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ var (
9898
// InitIssueIndexer initialize issue indexer, syncReindex is true then reindex until
9999
// all issue index done.
100100
func InitIssueIndexer(syncReindex bool) {
101-
waitChannel := make(chan time.Duration)
101+
waitChannel := make(chan time.Duration, 1)
102102

103103
// Create the Queue
104104
switch setting.Indexer.IssueType {

services/repository/archiver/archiver.go

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

0 commit comments

Comments
 (0)