Skip to content

Commit cddb610

Browse files
Fix go test -race issue
1 parent 0d8afaa commit cddb610

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

parser.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"regexp"
1818
"strconv"
1919
"strings"
20+
"sync"
2021
)
2122

2223
var (
@@ -68,6 +69,7 @@ type FileParser struct {
6869
started bool
6970
event *Event
7071
err error
72+
*sync.Mutex
7173
}
7274

7375
var Debug = false
@@ -86,13 +88,16 @@ func NewFileParser(file *os.File) *FileParser {
8688
queryLines: 0,
8789
lineOffset: 0,
8890
event: NewEvent(),
91+
Mutex: &sync.Mutex{},
8992
}
9093
return p
9194
}
9295

9396
// Stop stops the parser before parsing the next event or while blocked on
9497
// sending the current event to the event channel.
9598
func (p *FileParser) Stop() {
99+
p.Lock()
100+
defer p.Unlock()
96101
if Debug {
97102
log.Println("stopping")
98103
}
@@ -107,6 +112,8 @@ func (p *FileParser) Stop() {
107112
// Parsing stops on EOF, error, or call to Stop. The Events channel is closed
108113
// when parsing stops.
109114
func (p *FileParser) Start(opt Options) error {
115+
p.Lock()
116+
defer p.Unlock()
110117
if p.started {
111118
return ErrStarted
112119
}

0 commit comments

Comments
 (0)