From ad13ad8dbab82745e86fc3da89fcec3f71b7d2dd Mon Sep 17 00:00:00 2001 From: Dreamacro <305009791@qq.com> Date: Thu, 23 May 2019 23:27:29 +0800 Subject: [PATCH] Fix: add mutex for fake ip pool --- component/fakeip/pool.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/component/fakeip/pool.go b/component/fakeip/pool.go index 76c421e3..32d5d574 100644 --- a/component/fakeip/pool.go +++ b/component/fakeip/pool.go @@ -3,6 +3,7 @@ package fakeip import ( "errors" "net" + "sync" ) // Pool is a implementation about fake ip generator without storage @@ -10,10 +11,13 @@ type Pool struct { max uint32 min uint32 offset uint32 + mux *sync.Mutex } // Get return a new fake ip func (p *Pool) Get() net.IP { + p.mux.Lock() + defer p.mux.Unlock() ip := uintToIP(p.min + p.offset) p.offset = (p.offset + 1) % (p.max - p.min) return ip @@ -46,5 +50,6 @@ func New(ipnet *net.IPNet) (*Pool, error) { return &Pool{ min: min, max: max, + mux: &sync.Mutex{}, }, nil }