Fix stats collection bug
Okay I found the cause of the stats bug and it's unrelated to the memory bug. It happens because we're calling the clientAddr
function twice:
- first on the string extracted from the "client_ip" parameter
- second on the string we save in the clientMap
The first time we call this function, it turns 1.1.1.1
into a ClientMapAddr
that wraps a net.TCPAddr
. When we call String()
on this, it produces something like 1.1.1.1:1
(note the port). Then when we call clientAddr(1.1.1.1:1)
it returns an empty string because the call to net.ParseIP(1.1.1.1:1)
returns nil
because it's not an IP address.
There are multiple ways to solve this issue. I opted to just store values in the clientIDMap as net.Addr
instead of strings, since we convert them to net.Addr
before storing them in the map, and after we take them out of the map we convert them back into a net.Addr
anyway. However, we could solve this by changing how the clientAddr
function works instead.