Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 16e8bca

Browse files
committedSep 14, 2024
Avoid hanging: ensure we always close f.filesCh
The contract seems to be that the `walkFilesystem` goroutine is responsible for closing `f.filesCh`, but before this change, there were codepaths that could result in the gorouting exiting without closing `f.filesCh`. That shouldn't be possible anymore, so long as we keep this statement at the top of the function =) This fixes numtide#406
1 parent f927a83 commit 16e8bca

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed
 

‎cli/format.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,9 @@ func (f *Format) Run() (err error) {
201201

202202
func (f *Format) walkFilesystem(ctx context.Context) func() error {
203203
return func() error {
204+
// close the files channel when we're done walking the file system
205+
defer close(f.filesCh)
206+
204207
eg, ctx := errgroup.WithContext(ctx)
205208
pathsCh := make(chan string, BatchSize)
206209

@@ -261,9 +264,6 @@ func (f *Format) walkFilesystem(ctx context.Context) func() error {
261264
return fmt.Errorf("failed to create walker: %w", err)
262265
}
263266

264-
// close the files channel when we're done walking the file system
265-
defer close(f.filesCh)
266-
267267
// if no cache has been configured, or we are processing from stdin, we invoke the walker directly
268268
if f.NoCache || f.Stdin {
269269
return walker.Walk(ctx, func(file *walk.File, err error) error {

0 commit comments

Comments
 (0)
Please sign in to comment.