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 concurrency in ES client message buffer #54

Closed
wants to merge 1 commit into from

Conversation

csibbitt
Copy link
Contributor

"fatal error: concurrent map writes"
/go/src/github.com/infrawatch/sg-core/plugins/application/elasticsearch/main.go:95

/go/src/github.com/infrawatch/sg-core/pkg/bus.go:65 calls Application callbacks as a goroutine which results in concurrency in ReceiveEvent(). I've added a mutex to protect access.

"fatal error: concurrent map writes"
/go/src/github.com/infrawatch/sg-core/plugins/application/elasticsearch/main.go:95

/go/src/github.com/infrawatch/sg-core/pkg/bus.go:65 calls Application callbacks as a goroutine which results in concurrency in ReceiveEvent(). I've added a mutex to protect access.
@csibbitt
Copy link
Contributor Author

I've tested this and it fixes the problem; I can put 100k logs through the system and it doesn't crash, whereas before the fix (and when my fix didn't include protection for the initialization on L95) it would reliably crash before the first 10k. I am planning to compare it vs. #53 (developed concurrently) to see if there are any performance differences. I would expect this one to be faster anyways, but it's worth a shot just to see.

@csibbitt csibbitt requested review from paramite and pleimer June 14, 2021 19:54
Copy link
Contributor

@pleimer pleimer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am curious to see which one runs faster, although I too suspect this one will because of fewer calls to Lock() and Unlock() methods. The golang recommendation is to lock data types rather than methods because it helps to keep future developers from introducing concurrency bugs, but if this is more performant it's definitely worth it

@csibbitt
Copy link
Contributor Author

I'll be testing #53 and will prefer it if there is no obvious penalty.

The golang recommendation is to lock data types rather than methods because it helps to keep future developers from introducing concurrency bugs

Lol - except we already did that and the bug came anyways, right?

@pleimer
Copy link
Contributor

pleimer commented Jun 16, 2021

No? Not sure where you mean

@csibbitt
Copy link
Contributor Author

csibbitt commented Jun 16, 2021

No? Not sure where you mean

I mean we already had a locked datatype at hand, but the concurrency bug appeared anyways since it wasn't used. I understand you meant something slightly different.

In any case, I'm trying to pull together a lab to test #53 today. Hope to merge it by EOD

@csibbitt
Copy link
Contributor Author

Closed in favor of #53

@csibbitt csibbitt closed this Jun 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants