Skip to content

Commit

Permalink
Merge branch 'Fix_race_conditionon_EOF'
Browse files Browse the repository at this point in the history
  • Loading branch information
7ail committed Sep 19, 2019
2 parents 1bb02a2 + c5e94d2 commit 44ffa92
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
7 changes: 1 addition & 6 deletions jqpipe.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,6 @@ func (p *Pipe) Next() (json.RawMessage, error) {
}
p.stdout.Close()

if err == io.EOF {
p.jq.Wait()
return nil, err
}

// if we have a decoding error, jq is sick and we need to kill it with fire..
if err != io.EOF {
p.Close()
Expand All @@ -102,7 +97,7 @@ func (p *Pipe) Next() (json.RawMessage, error) {
return nil, errors.New(p.stderr.String())
}

if p.jq.ProcessState.Success() {
if p.jq.ProcessState.Success() || err == io.EOF {
return nil, io.EOF
}

Expand Down
20 changes: 20 additions & 0 deletions jqpipe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package jq

import (
"encoding/json"
"sync"
"testing"
)

Expand Down Expand Up @@ -60,3 +61,22 @@ func failEval(t *testing.T, inp, expr string, results []json.RawMessage, layout
t.Errorf(layout, info...)
return false
}

func TestJQEvalRaceCondition(t *testing.T) {
t.Parallel()

var wg sync.WaitGroup
for i := 0; i < 100; i++ {
wg.Add(1)
go func() {
defer wg.Done()

_, err := Eval(`{ "foo": { "bar": { "baz": 123 } } }`, ".")
if err != nil {
t.Errorf("err should be nil: %s", err)
}
}()
}

wg.Wait()
}

0 comments on commit 44ffa92

Please sign in to comment.