mirror of
https://github.com/yannh/kubeconform.git
synced 2026-02-11 14:09:21 +00:00
fix race condition when shutting down
This commit is contained in:
parent
3a2d4705f5
commit
94f8e9e631
2 changed files with 9 additions and 15 deletions
|
|
@ -43,21 +43,18 @@ func isIgnored(path string, ignoreFilePatterns []string) (bool, error) {
|
|||
func FromFiles(ctx context.Context, ignoreFilePatterns []string, paths ...string) (<-chan Resource, <-chan error) {
|
||||
resources := make(chan Resource)
|
||||
errors := make(chan error)
|
||||
stop := false
|
||||
|
||||
go func() {
|
||||
<-ctx.Done()
|
||||
stop = true
|
||||
}()
|
||||
|
||||
go func() {
|
||||
for _, path := range paths {
|
||||
// we handle errors in the walk function directly
|
||||
// so it should be safe to discard the outer error
|
||||
err := filepath.Walk(path, func(p string, i os.FileInfo, err error) error {
|
||||
if stop == true {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return io.EOF
|
||||
default:
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,20 +42,17 @@ func SplitYAMLDocument(data []byte, atEOF bool) (advance int, token []byte, err
|
|||
func FromStream(ctx context.Context, path string, r io.Reader) (<-chan Resource, <-chan error) {
|
||||
resources := make(chan Resource)
|
||||
errors := make(chan error)
|
||||
stop := false
|
||||
|
||||
go func() {
|
||||
<-ctx.Done()
|
||||
stop = true
|
||||
}()
|
||||
|
||||
go func() {
|
||||
scanner := bufio.NewScanner(r)
|
||||
scanner.Split(SplitYAMLDocument)
|
||||
|
||||
SCAN:
|
||||
for res := scanner.Scan(); res != false; res = scanner.Scan() {
|
||||
if stop == true {
|
||||
break
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
break SCAN
|
||||
default:
|
||||
}
|
||||
resources <- Resource{Path: path, Bytes: scanner.Bytes()}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue