Skip to content

Commit acdf265

Browse files
committed
Fix reader regression (#4070)
1 parent 19495eb commit acdf265

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/reader.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ type Reader struct {
2424
event int32
2525
finChan chan bool
2626
mutex sync.Mutex
27+
killed bool
2728
termFunc func()
2829
command *string
2930
wait bool
@@ -39,6 +40,7 @@ func NewReader(pusher func([]byte) bool, eventBox *util.EventBox, executor *util
3940
int32(EvtReady),
4041
make(chan bool, 1),
4142
sync.Mutex{},
43+
false,
4244
func() { os.Stdin.Close() },
4345
nil,
4446
wait}
@@ -68,10 +70,6 @@ func (r *Reader) startEventPoller() {
6870
}()
6971
}
7072

71-
func (r *Reader) wasKilled() bool {
72-
return r.termFunc == nil
73-
}
74-
7573
func (r *Reader) fin(success bool) {
7674
atomic.StoreInt32(&r.event, int32(EvtReadFin))
7775
if r.wait {
@@ -80,7 +78,7 @@ func (r *Reader) fin(success bool) {
8078

8179
r.mutex.Lock()
8280
ret := r.command
83-
if success || r.wasKilled() {
81+
if success || r.killed {
8482
ret = nil
8583
}
8684
r.mutex.Unlock()
@@ -90,6 +88,7 @@ func (r *Reader) fin(success bool) {
9088

9189
func (r *Reader) terminate() {
9290
r.mutex.Lock()
91+
r.killed = true
9392
if r.termFunc != nil {
9493
r.termFunc()
9594
r.termFunc = nil
@@ -297,7 +296,7 @@ func (r *Reader) readFiles(root string, opts walkerOpts, ignores []string) bool
297296
}
298297
r.mutex.Lock()
299298
defer r.mutex.Unlock()
300-
if r.wasKilled() {
299+
if r.killed {
301300
return context.Canceled
302301
}
303302
return nil
@@ -308,6 +307,7 @@ func (r *Reader) readFiles(root string, opts walkerOpts, ignores []string) bool
308307
func (r *Reader) readFromCommand(command string, environ []string, signalReady func()) bool {
309308
r.mutex.Lock()
310309

310+
r.killed = false
311311
r.termFunc = nil
312312
r.command = &command
313313
exec := r.executor.ExecCommand(command, true)
@@ -316,6 +316,7 @@ func (r *Reader) readFromCommand(command string, environ []string, signalReady f
316316
}
317317
execOut, err := exec.StdoutPipe()
318318
if err != nil || exec.Start() != nil {
319+
signalReady()
319320
r.mutex.Unlock()
320321
return false
321322
}

0 commit comments

Comments
 (0)