@@ -93,10 +93,17 @@ type Handler interface {
9393 // ConnectionClosed is called when a connection is closed.
9494 ConnectionClosed (c * Conn )
9595
96+ // ConnectionAuthenticated is called when a connection is authenticated.
97+ // Always called after NewConnection and before ConnectionClosed.
98+ ConnectionAuthenticated (* Conn ) error
99+
96100 // ConnectionAborted is called when a new connection cannot be fully established. For
97101 // example, if a client connects to the server, but fails authentication, or can't
98102 // negotiate an authentication handshake, this method will be called to let integrators
99103 // know about the failed connection attempt.
104+ //
105+ // ConnectionClosed will still be called for the connection after ConnectionAborted is
106+ // called.
100107 ConnectionAborted (c * Conn , reason string ) error
101108
102109 // ComInitDB is called once at the beginning to set db name,
@@ -560,6 +567,13 @@ func (l *Listener) handle(ctx context.Context, conn net.Conn, connectionID uint3
560567 defer connCountPerUser .Add (c .User , - 1 )
561568 }
562569
570+ if err = l .handler .ConnectionAuthenticated (c ); err != nil {
571+ log .Errorf ("failed to register the connection as authenticated %s: %v" , c , err )
572+
573+ c .writeErrorPacketFromError (err )
574+ return
575+ }
576+
563577 // Set initial db name.
564578 if c .schemaName != "" {
565579 if err = l .handler .ComInitDB (c , c .schemaName ); err != nil {
0 commit comments