We are using https://github.com/dlmiddlecote/sqlstats to expose the connection metrics, setting maxOpenConns to 300, and maxIdleConns to 220. The metrics graph is
We can see there are a lot of idle connections in the first graph. But the server is also closing connections due to max idle connections reached. I believe this means that the sql.DB package is creating more connections than maxIdleConn, and later has to remove them. But, looking at the first graph, why does sql.DB need to create more connections and exceed maxIidleConn if there are a lot of idle connections around already?

