Skip to content

Connection count metric can be less than the real value #51889

Closed
@YangKeao

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:

  1. Don't include any logic in conn.Close(). Only have logic in the sync.Once inside the closeConn.
  2. Enhance the code, don't close the connection for multiple times! (it's more intuitive for the developers).

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions