-
Notifications
You must be signed in to change notification settings - Fork 712
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
Avoid race conditions in DNSSnooper's cached domains #2637
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really want such fine-grained locking? Rather than a single lock.
// Not worth using a RMutex since we don't expect a lot of contention | ||
// and they are considerably larger (8 bytes vs 24 bytes), which would | ||
// bloat the cache | ||
sync.Mutex |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
I started with a global lock, but I figured there would be some contention and locks are small (8 bytes). As a nice side-effect, the code is more readable (it's obvious what the mutex guards). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would have done this differently, as per my comment, but if you want to squash & merge as is then that's fine.
// bloat the cache | ||
mutex *sync.Mutex | ||
domains map[string]struct{} | ||
} |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
Alright, I caved in (midsommar-good-mood :) ) and modified the code to use a global mutex instead. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small typo. Rest is LGTM.
stop chan struct{} | ||
pcapHandle *pcap.Handle | ||
// gcache is goroutine-safe, but the | ||
// values cached values aren't |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
Fixes #2636