Skip to content

Commit

Permalink
backend: closed before/after handshake (#157)
Browse files Browse the repository at this point in the history
  • Loading branch information
xhebox authored Dec 22, 2022
1 parent 8aee2ce commit b5d2300
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
4 changes: 3 additions & 1 deletion pkg/proxy/backend/backend_conn_mgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ type BackendConnManager struct {
handshakeHandler HandshakeHandler
getBackendIO backendIOGetter
connectionID uint64
handshaked bool
}

// NewBackendConnManager creates a BackendConnManager.
Expand Down Expand Up @@ -165,6 +166,7 @@ func (mgr *BackendConnManager) Connect(ctx context.Context, clientIO *pnet.Packe
mgr.wg.Run(func() {
mgr.processSignals(childCtx, clientIO)
})
mgr.handshaked = true
return nil
}

Expand Down Expand Up @@ -409,7 +411,7 @@ func (mgr *BackendConnManager) Close() error {
}
mgr.processLock.Unlock()

handErr := mgr.handshakeHandler.OnConnClose(mgr.authenticator)
handErr := mgr.handshakeHandler.OnConnClose(mgr.authenticator, mgr.handshaked)

eventReceiver := mgr.getEventReceiver()
if eventReceiver != nil {
Expand Down
4 changes: 2 additions & 2 deletions pkg/proxy/backend/handshake_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type ConnContext interface {
type HandshakeHandler interface {
HandleHandshakeResp(ctx ConnContext, resp *pnet.HandshakeResp) error
GetRouter(ctx ConnContext, resp *pnet.HandshakeResp) (router.Router, error)
OnConnClose(ctx ConnContext) error
OnConnClose(ctx ConnContext, handshaked bool) error
GetCapability() pnet.Capability
}

Expand Down Expand Up @@ -71,7 +71,7 @@ func (handler *DefaultHandshakeHandler) GetRouter(ctx ConnContext, resp *pnet.Ha
return ns.GetRouter(), nil
}

func (handler *DefaultHandshakeHandler) OnConnClose(ConnContext) error {
func (handler *DefaultHandshakeHandler) OnConnClose(ConnContext, bool) error {
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/proxy/backend/mock_proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func (handler *CustomHandshakeHandler) GetRouter(ctx ConnContext, resp *pnet.Han
return nil, nil
}

func (handler *CustomHandshakeHandler) OnConnClose(ctx ConnContext) error {
func (handler *CustomHandshakeHandler) OnConnClose(ctx ConnContext, _ bool) error {
return nil
}

Expand Down

0 comments on commit b5d2300

Please sign in to comment.