Connection count metric can be less than the real value #51889
Closed
Description
This issue has similar reason with #42761, because the conn.Close()
will be called multiple times 🤦.
func (s *Server) onConn(conn *clientConn) {
...
defer func() {
terror.Log(conn.Close())
logutil.Logger(ctx).Debug("connection closed")
}()
...
}
And
func (cc *clientConn) Run(ctx context.Context) {
defer func() {
...
if cc.getStatus() != connStatusShutdown {
err := cc.Close()
terror.Log(err)
}
close(cc.quit)
}()
We have two ways to solve this problem:
- Don't include any logic in
conn.Close()
. Only have logic in thesync.Once
inside thecloseConn
. - Enhance the code, don't close the connection for multiple times! (it's more intuitive for the developers).