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

Avoid race conditions in DNSSnooper's cached domains #2637

Merged
merged 4 commits into from
Jun 23, 2017

Conversation

2opremio
Copy link
Contributor

Fixes #2636

Copy link
Member

@rade rade left a 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.

This comment was marked as abuse.

This comment was marked as abuse.

This comment was marked as abuse.

@2opremio
Copy link
Contributor Author

2opremio commented Jun 22, 2017

Do we really want such fine-grained locking? Rather than a single lock.

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).

Copy link
Member

@rade rade left a 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.

@2opremio
Copy link
Contributor Author

Alright, I caved in (midsommar-good-mood :) ) and modified the code to use a global mutex instead.

Copy link
Member

@rade rade left a 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.

@2opremio 2opremio merged commit 40bb28a into master Jun 23, 2017
@2opremio 2opremio deleted the 2636-DNSSnooper-race branch June 23, 2017 23:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants