From 829c7af1bc8375f69a15013a3aef5d6225019310 Mon Sep 17 00:00:00 2001 From: kenshinx Date: Thu, 18 May 2017 17:29:56 +0800 Subject: [PATCH] fix: concurrent iteration map need lock. --- hosts.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hosts.go b/hosts.go index 25557b4..cdc251f 100644 --- a/hosts.go +++ b/hosts.go @@ -101,10 +101,10 @@ type RedisHosts struct { } func (r *RedisHosts) Get(domain string) ([]string, bool) { - domain = strings.ToLower(domain) r.mu.RLock() + defer r.mu.RUnlock() + domain = strings.ToLower(domain) ip, ok := r.hosts[domain] - r.mu.RUnlock() if ok { return strings.Split(ip, ","), true }