-
Notifications
You must be signed in to change notification settings - Fork 2
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 cache race #4
Conversation
sync.RWMutex | ||
mx sync.Mutex |
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.
Figured exporting the Lock/Unlock functions here was unintentional and a bad idea for a consumer to use.
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.
ah yes, it was just programmatic convenience!
@@ -101,8 +101,8 @@ func (r *Resolver) LookupTXT(ctx context.Context, domain string) ([]string, erro | |||
} | |||
|
|||
func (r *Resolver) getCachedIPAddr(domain string) ([]net.IPAddr, bool) { | |||
r.RLock() | |||
defer r.RUnlock() | |||
r.mx.Lock() |
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.
Switching away from RW mutexes may slow things down here. Given that we're caching against what would be a network request waiting on a mutex doesn't feel too bad, and if this becomes an issue we can always come back and optimize it.
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.
let's add a follow up issue? It shouldn't be hard to do, just queue the entries for cleanup and do that with write lock.
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.
sync.RWMutex | ||
mx sync.Mutex |
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.
ah yes, it was just programmatic convenience!
@@ -101,8 +101,8 @@ func (r *Resolver) LookupTXT(ctx context.Context, domain string) ([]string, erro | |||
} | |||
|
|||
func (r *Resolver) getCachedIPAddr(domain string) ([]net.IPAddr, bool) { | |||
r.RLock() | |||
defer r.RUnlock() | |||
r.mx.Lock() |
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.
let's add a follow up issue? It shouldn't be hard to do, just queue the entries for cleanup and do that with write lock.
No description provided.