Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
K
koko
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ops
koko
Commits
4933b6fd
Commit
4933b6fd
authored
Jun 12, 2019
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Update] 修改连接缓存问题
parent
ac2c1d8f
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
23 additions
and
15 deletions
+23
-15
proxy.go
pkg/proxy/proxy.go
+1
-1
connmanager.go
pkg/srvconn/connmanager.go
+20
-13
sshconn.go
pkg/srvconn/sshconn.go
+2
-1
No files found.
pkg/proxy/proxy.go
View file @
4933b6fd
...
@@ -189,7 +189,7 @@ func (p *ProxyServer) preCheckRequisite() (ok bool) {
...
@@ -189,7 +189,7 @@ func (p *ProxyServer) preCheckRequisite() (ok bool) {
// sendConnectErrorMsg 发送连接错误消息
// sendConnectErrorMsg 发送连接错误消息
func
(
p
*
ProxyServer
)
sendConnectErrorMsg
(
err
error
)
{
func
(
p
*
ProxyServer
)
sendConnectErrorMsg
(
err
error
)
{
msg
:=
fmt
.
Sprintf
(
"Connect asset %s error: %s"
,
p
.
Asset
.
Hostname
,
err
)
msg
:=
fmt
.
Sprintf
(
"Connect asset %s error: %s
\r\n
"
,
p
.
Asset
.
Hostname
,
err
)
utils
.
IgnoreErrWriteString
(
p
.
UserConn
,
msg
)
utils
.
IgnoreErrWriteString
(
p
.
UserConn
,
msg
)
logger
.
Error
(
msg
)
logger
.
Error
(
msg
)
password
:=
p
.
SystemUser
.
Password
password
:=
p
.
SystemUser
.
Password
...
...
pkg/srvconn/connmanager.go
View file @
4933b6fd
package
srvconn
package
srvconn
import
(
import
(
"github.com/jumpserver/koko/pkg/service"
"encoding/json"
"encoding/json"
"errors"
"errors"
"fmt"
"fmt"
"github.com/jumpserver/koko/pkg/service"
"net"
"net"
"strconv"
"strconv"
"sync"
"sync"
...
@@ -209,21 +209,28 @@ func RecycleClient(client *gossh.Client) {
...
@@ -209,21 +209,28 @@ func RecycleClient(client *gossh.Client) {
if
counter
,
ok
:=
clientsRefCounter
[
client
];
ok
{
if
counter
,
ok
:=
clientsRefCounter
[
client
];
ok
{
if
counter
==
1
{
if
counter
==
1
{
logger
.
Debug
(
"Recycle client: close it"
)
logger
.
Debug
(
"Recycle client: close it"
)
_
=
client
.
Close
()
CloseClient
(
client
)
delete
(
clientsRefCounter
,
client
)
var
key
string
for
k
,
v
:=
range
sshClients
{
if
v
==
client
{
key
=
k
break
}
}
if
key
!=
""
{
delete
(
sshClients
,
key
)
}
}
else
{
}
else
{
clientsRefCounter
[
client
]
--
clientsRefCounter
[
client
]
--
logger
.
Debugf
(
"Recycle client: ref -1: %d"
,
clientsRefCounter
[
client
])
logger
.
Debugf
(
"Recycle client: ref -1: %d"
,
clientsRefCounter
[
client
])
}
}
}
}
}
}
func
CloseClient
(
client
*
gossh
.
Client
)
{
clientLock
.
Lock
()
defer
clientLock
.
Unlock
()
delete
(
clientsRefCounter
,
client
)
var
key
string
for
k
,
v
:=
range
sshClients
{
if
v
==
client
{
key
=
k
break
}
}
if
key
!=
""
{
delete
(
sshClients
,
key
)
}
_
=
client
.
Close
()
}
pkg/srvconn/sshconn.go
View file @
4933b6fd
...
@@ -72,10 +72,11 @@ func (sc *ServerSSHConnection) Connect(h, w int, term string) (err error) {
...
@@ -72,10 +72,11 @@ func (sc *ServerSSHConnection) Connect(h, w int, term string) (err error) {
func
(
sc
*
ServerSSHConnection
)
TryConnectFromCache
(
h
,
w
int
,
term
string
)
(
err
error
)
{
func
(
sc
*
ServerSSHConnection
)
TryConnectFromCache
(
h
,
w
int
,
term
string
)
(
err
error
)
{
sc
.
client
=
GetClientFromCache
(
sc
.
User
,
sc
.
Asset
,
sc
.
SystemUser
)
sc
.
client
=
GetClientFromCache
(
sc
.
User
,
sc
.
Asset
,
sc
.
SystemUser
)
if
sc
.
client
==
nil
{
if
sc
.
client
==
nil
{
return
errors
.
New
(
"
N
o client in cache"
)
return
errors
.
New
(
"
n
o client in cache"
)
}
}
err
=
sc
.
invokeShell
(
h
,
w
,
term
)
err
=
sc
.
invokeShell
(
h
,
w
,
term
)
if
err
!=
nil
{
if
err
!=
nil
{
CloseClient
(
sc
.
client
)
return
return
}
}
sc
.
connected
=
true
sc
.
connected
=
true
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment