Skip to content

Commit

Permalink
Handle case when context is canceled before any results are sent to t…
Browse files Browse the repository at this point in the history
…he results channel
  • Loading branch information
estolfo committed Jul 27, 2021
1 parent 2f1d8e3 commit 5a7dd1c
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions sourcemap/fleet_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,10 @@ func (f fleetStore) fetch(ctx context.Context, name, version, path string) (stri
go func(fleetURL string) {
defer wg.Done()
sourcemap, err := sendRequest(f, ctx, fleetURL)
results <- result{sourcemap, err}
select {
case <-ctx.Done():
case results <- result{sourcemap, err}:
}
}(baseURL + sourceMapURL)
}

Expand All @@ -142,8 +145,13 @@ func (f fleetStore) fetch(ctx context.Context, name, version, path string) (stri
}
}

// All requests resulted in a query failure
return "", err
if err == nil {
// None of the goroutines sent a result to the results channel
return "", ctx.Err()
} else {
// All requests resulted in a query failure
return "", err
}
}

func sendRequest(f fleetStore, ctx context.Context, fleetURL string) (string, error) {
Expand Down

0 comments on commit 5a7dd1c

Please sign in to comment.