Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix data race in mockbeat (#5037) #5426

Merged
merged 1 commit into from
Oct 24, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions libbeat/mock/mockbeat.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ var Version = "9.9.9"
var Name = "mockbeat"

type Mockbeat struct {
done chan struct{}
client beat.Client
done chan struct{}
}

// Creates beater
Expand All @@ -28,15 +27,13 @@ func New(b *beat.Beat, _ *common.Config) (beat.Beater, error) {
/// *** Beater interface methods ***///

func (mb *Mockbeat) Run(b *beat.Beat) error {
var err error

mb.client, err = b.Publisher.Connect()
client, err := b.Publisher.Connect()
if err != nil {
return err
}

// Wait until mockbeat is done
mb.client.Publish(beat.Event{
go client.Publish(beat.Event{
Timestamp: time.Now(),
Fields: common.MapStr{
"type": "mock",
Expand All @@ -50,6 +47,5 @@ func (mb *Mockbeat) Run(b *beat.Beat) error {
func (mb *Mockbeat) Stop() {
logp.Info("Mockbeat Stop")

mb.client.Close()
close(mb.done)
}