From 339bac921ffe131bc6d3da9cf824e0178c1b13a5 Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Sat, 7 Jul 2018 13:23:00 +0900 Subject: [PATCH] Prevent multiple IP lookups --- middleware/IPToHost.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/middleware/IPToHost.go b/middleware/IPToHost.go index 2a138b7a..cd085723 100644 --- a/middleware/IPToHost.go +++ b/middleware/IPToHost.go @@ -2,15 +2,20 @@ package middleware import ( "net" + "sync" "time" cache "github.com/patrickmn/go-cache" ) var ipToHosts = cache.New(60*time.Minute, 30*time.Minute) +var ipToHostsMutex sync.Mutex // GetHostsForIP returns all host names for the given IP (if cached). func GetHostsForIP(ip string) ([]string, bool) { + ipToHostsMutex.Lock() + defer ipToHostsMutex.Unlock() + hosts, found := ipToHosts.Get(ip) if !found {