Skip to content

Commit

Permalink
lfs/gitscanner_catfilebatchcheck.go: close channel
Browse files Browse the repository at this point in the history
In commit 08c5ae6 of PR #1953 the
runCatFileBatchCheck() and runCatFileBatch() functions of the "lfs"
package were updated to write the pathspecs of locked files which are
not Git LFS pointers to a dedicated channel created by the
catFileBatchCheck() and catFileBatch() wrapper functions, respectively.

The scanRefsToChan() function, which calls both of these with a
potentially non-nil *lockableNameSet paramter (and is the only caller
to do so), starts a goroutine with an anonymous function to read any
events on the channel returned by catFileBatchCheck(), and then reads
all events on the channel returned by catFileBatch() directly.  In the
latter case, this would cause scanRefsToChan() to stall indefinitely
unless the channel is closed, so the anonymous function started by the
runCatFileBatch() function that writes to the channel always closes
the channel upon exit.

However, the anonymous function started by the runCatFileBatchCheck()
function that writes to its lock path channel does not do the same.
While this does not cause a stalled program because scanRefsToChan()
creates its own anonymous function to read from the channel, that
function will not exit until the progam stops.

By adding an explicit close() of the channel at the end of the
anonymous function started by runCatFileBatchCheck(), we can ensure
the anonymous function which reads that channel will also exit
as soon as possible.
  • Loading branch information
chrisd8088 committed Jun 7, 2023
1 parent a3e953d commit 8c16837
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions lfs/gitscanner_catfilebatchcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ func runCatFileBatchCheck(smallRevCh chan string, lockableCh chan string, lockab
}
close(smallRevCh)
close(errCh)
close(lockableCh)
}()

return nil
Expand Down

0 comments on commit 8c16837

Please sign in to comment.