Commit f15b0990 authored by ibuler's avatar ibuler

[Bugfix] 修复锁无法释放的问题

parent 286c0e8f
...@@ -52,7 +52,7 @@ func (dt *DirectTransport) Keep() { ...@@ -52,7 +52,7 @@ func (dt *DirectTransport) Keep() {
if !dt.closed { if !dt.closed {
dt.ch <- buf[:n] dt.ch <- buf[:n]
} else { } else {
logger.Debug("Transport ") logger.Debug("Transport closed")
break break
} }
} }
......
package srvconn package srvconn
import ( import (
"encoding/json"
"errors" "errors"
"fmt" "fmt"
"github.com/jumpserver/koko/pkg/service" "github.com/jumpserver/koko/pkg/service"
...@@ -67,8 +66,6 @@ func (sc *SSHClientConfig) Config() (config *gossh.ClientConfig, err error) { ...@@ -67,8 +66,6 @@ func (sc *SSHClientConfig) Config() (config *gossh.ClientConfig, err error) {
func (sc *SSHClientConfig) DialProxy() (client *gossh.Client, err error) { func (sc *SSHClientConfig) DialProxy() (client *gossh.Client, err error) {
for _, p := range sc.Proxy { for _, p := range sc.Proxy {
data, _ := json.Marshal(p)
fmt.Println(string(data))
client, err = p.Dial() client, err = p.Dial()
if err == nil { if err == nil {
logger.Debugf("Connect proxy host %s:%s success", p.Host, p.Port) logger.Debugf("Connect proxy host %s:%s success", p.Host, p.Port)
...@@ -197,15 +194,18 @@ func GetClientFromCache(user *model.User, asset *model.Asset, systemUser *model. ...@@ -197,15 +194,18 @@ func GetClientFromCache(user *model.User, asset *model.Asset, systemUser *model.
} }
func RecycleClient(client *gossh.Client) { func RecycleClient(client *gossh.Client) {
clientLock.Lock() clientLock.RLock()
defer clientLock.Unlock() counter, ok := clientsRefCounter[client]
clientLock.RUnlock()
if counter, ok := clientsRefCounter[client]; ok { if ok {
if counter == 1 { if counter == 1 {
logger.Debug("Recycle client: close it") logger.Debug("Recycle client: close it")
CloseClient(client) CloseClient(client)
} else { } else {
clientLock.Lock()
clientsRefCounter[client]-- clientsRefCounter[client]--
clientLock.Unlock()
logger.Debugf("Recycle client: ref -1: %d", clientsRefCounter[client]) logger.Debugf("Recycle client: ref -1: %d", clientsRefCounter[client])
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment