mirror of
https://github.com/kubenetworks/kubevpn.git
synced 2025-12-24 11:51:13 +08:00
hotfix: cancel ctx (#246)
This commit is contained in:
@@ -11,9 +11,9 @@ import (
|
||||
|
||||
var CancelFunc = make(map[string]context.CancelFunc)
|
||||
|
||||
func (svr *Server) ConfigAdd(ctx context.Context, req *rpc.ConfigAddRequest) (*rpc.ConfigAddResponse, error) {
|
||||
var sshConf = util.ParseSshFromRPC(req.SshJump)
|
||||
file, err := util.ConvertToTempKubeconfigFile([]byte(req.KubeconfigBytes))
|
||||
func (svr *Server) ConfigAdd(ctx context.Context, req *rpc.ConfigAddRequest) (resp *rpc.ConfigAddResponse, err error) {
|
||||
var file string
|
||||
file, err = util.ConvertToTempKubeconfigFile([]byte(req.KubeconfigBytes))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -23,13 +23,19 @@ func (svr *Server) ConfigAdd(ctx context.Context, req *rpc.ConfigAddRequest) (*r
|
||||
DefValue: file,
|
||||
})
|
||||
sshCtx, sshCancel := context.WithCancel(context.Background())
|
||||
defer func() {
|
||||
if err != nil {
|
||||
sshCancel()
|
||||
}
|
||||
}()
|
||||
var path string
|
||||
var sshConf = util.ParseSshFromRPC(req.SshJump)
|
||||
path, err = util.SshJump(sshCtx, sshConf, flags, true)
|
||||
CancelFunc[path] = sshCancel
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
CancelFunc[path] = sshCancel
|
||||
return &rpc.ConfigAddResponse{ClusterID: path}, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -66,6 +66,7 @@ func (svr *Server) ConnectFork(req *rpc.ConnectRequest, resp rpc.Daemon_ConnectF
|
||||
defer func() {
|
||||
if err != nil {
|
||||
connect.Cleanup()
|
||||
sshCancel()
|
||||
}
|
||||
}()
|
||||
|
||||
@@ -98,7 +99,7 @@ func (svr *Server) ConnectFork(req *rpc.ConnectRequest, resp rpc.Daemon_ConnectF
|
||||
return nil
|
||||
}
|
||||
|
||||
func (svr *Server) redirectConnectForkToSudoDaemon(req *rpc.ConnectRequest, resp rpc.Daemon_ConnectServer) error {
|
||||
func (svr *Server) redirectConnectForkToSudoDaemon(req *rpc.ConnectRequest, resp rpc.Daemon_ConnectServer) (err error) {
|
||||
cli := svr.GetClient(true)
|
||||
if cli == nil {
|
||||
return fmt.Errorf("sudo daemon not start")
|
||||
@@ -126,6 +127,11 @@ func (svr *Server) redirectConnectForkToSudoDaemon(req *rpc.ConnectRequest, resp
|
||||
sshCancel()
|
||||
return nil
|
||||
})
|
||||
defer func() {
|
||||
if err != nil {
|
||||
sshCancel()
|
||||
}
|
||||
}()
|
||||
var path string
|
||||
path, err = util.SshJump(sshCtx, sshConf, flags, true)
|
||||
if err != nil {
|
||||
|
||||
@@ -83,6 +83,11 @@ func (svr *Server) Connect(req *rpc.ConnectRequest, resp rpc.Daemon_ConnectServe
|
||||
sshCancel()
|
||||
return nil
|
||||
})
|
||||
defer func() {
|
||||
if e != nil {
|
||||
sshCancel()
|
||||
}
|
||||
}()
|
||||
var path string
|
||||
path, err = util.SshJump(sshCtx, sshConf, flags, false)
|
||||
if err != nil {
|
||||
@@ -113,7 +118,7 @@ func (svr *Server) Connect(req *rpc.ConnectRequest, resp rpc.Daemon_ConnectServe
|
||||
return nil
|
||||
}
|
||||
|
||||
func (svr *Server) redirectToSudoDaemon(req *rpc.ConnectRequest, resp rpc.Daemon_ConnectServer) error {
|
||||
func (svr *Server) redirectToSudoDaemon(req *rpc.ConnectRequest, resp rpc.Daemon_ConnectServer) (e error) {
|
||||
cli := svr.GetClient(true)
|
||||
if cli == nil {
|
||||
return fmt.Errorf("sudo daemon not start")
|
||||
@@ -142,6 +147,11 @@ func (svr *Server) redirectToSudoDaemon(req *rpc.ConnectRequest, resp rpc.Daemon
|
||||
sshCancel()
|
||||
return nil
|
||||
})
|
||||
defer func() {
|
||||
if e != nil {
|
||||
sshCancel()
|
||||
}
|
||||
}()
|
||||
var path string
|
||||
path, err = util.SshJump(sshCtx, sshConf, flags, true)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user