ctx := context.Background() for { conn, err := l.listener.Accept() if err != nil { // Close() was probably called. // 想要走到这里,执行这行代码 connRefuse.Add(1) return } acceptTime := time.Now() connectionID := l.connectionID l.connectionID++ connCount.Add(1) connAccept.Add(1) go func() { if l.PreHandleFunc != nil { conn, err = l.PreHandleFunc(ctx, conn, connectionID) if err != nil { log.Errorf("mysql_server pre hook: %s", err) return } } l.handle(conn, connectionID, acceptTime) }() } 