From 5f7bb8a8db09b11601ddc22ab78f200c8a5f4d87 Mon Sep 17 00:00:00 2001 From: "jesse.liston" Date: Thu, 2 Feb 2023 23:37:19 -0800 Subject: [PATCH 1/2] use FIFO queue for freelist --- memcache/memcache.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/memcache/memcache.go b/memcache/memcache.go index b536d384..9013e568 100644 --- a/memcache/memcache.go +++ b/memcache/memcache.go @@ -224,8 +224,8 @@ func (c *Client) getFreeConn(addr net.Addr) (cn *conn, ok bool) { if !ok || len(freelist) == 0 { return nil, false } - cn = freelist[len(freelist)-1] - c.freeconn[addr.String()] = freelist[:len(freelist)-1] + cn = freelist[0] + c.freeconn[addr.String()] = freelist[1:] return cn, true } From c52052474d42e92576e23c05e3961adefac789e2 Mon Sep 17 00:00:00 2001 From: "jesse.liston" Date: Fri, 3 Feb 2023 00:11:58 -0800 Subject: [PATCH 2/2] use copy and overwrite last item --- memcache/memcache.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/memcache/memcache.go b/memcache/memcache.go index 9013e568..dca6a745 100644 --- a/memcache/memcache.go +++ b/memcache/memcache.go @@ -225,7 +225,8 @@ func (c *Client) getFreeConn(addr net.Addr) (cn *conn, ok bool) { return nil, false } cn = freelist[0] - c.freeconn[addr.String()] = freelist[1:] + copy(c.freeconn[addr.String()], freelist[1:]) + c.freeconn[addr.String()] = freelist[:len(freelist)-1] return cn, true }