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
286c0e8f
Commit
286c0e8f
authored
Jun 12, 2019
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Update] 修改连接缓存问题
parent
4933b6fd
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
16 deletions
+10
-16
connmanager.go
pkg/srvconn/connmanager.go
+10
-16
No files found.
pkg/srvconn/connmanager.go
View file @
286c0e8f
...
@@ -161,25 +161,12 @@ func newClient(asset *model.Asset, systemUser *model.SystemUser, timeout time.Du
...
@@ -161,25 +161,12 @@ func newClient(asset *model.Asset, systemUser *model.SystemUser, timeout time.Du
}
}
func
NewClient
(
user
*
model
.
User
,
asset
*
model
.
Asset
,
systemUser
*
model
.
SystemUser
,
timeout
time
.
Duration
)
(
client
*
gossh
.
Client
,
err
error
)
{
func
NewClient
(
user
*
model
.
User
,
asset
*
model
.
Asset
,
systemUser
*
model
.
SystemUser
,
timeout
time
.
Duration
)
(
client
*
gossh
.
Client
,
err
error
)
{
key
:=
fmt
.
Sprintf
(
"%s_%s_%s"
,
user
.
ID
,
asset
.
ID
,
systemUser
.
ID
)
client
=
GetClientFromCache
(
user
,
asset
,
systemUser
)
clientLock
.
RLock
()
if
client
!=
nil
{
client
,
ok
:=
sshClients
[
key
]
clientLock
.
RUnlock
()
var
u
=
user
.
Username
var
ip
=
asset
.
IP
var
sysName
=
systemUser
.
Username
if
ok
{
clientLock
.
Lock
()
clientsRefCounter
[
client
]
++
var
counter
=
clientsRefCounter
[
client
]
logger
.
Infof
(
"Reuse connection: %s->%s@%s ref: %d"
,
u
,
sysName
,
ip
,
counter
)
clientLock
.
Unlock
()
return
client
,
nil
return
client
,
nil
}
}
key
:=
fmt
.
Sprintf
(
"%s_%s_%s"
,
user
.
ID
,
asset
.
ID
,
systemUser
.
ID
)
client
,
err
=
newClient
(
asset
,
systemUser
,
timeout
)
client
,
err
=
newClient
(
asset
,
systemUser
,
timeout
)
if
err
==
nil
{
if
err
==
nil
{
clientLock
.
Lock
()
clientLock
.
Lock
()
...
@@ -198,7 +185,14 @@ func GetClientFromCache(user *model.User, asset *model.Asset, systemUser *model.
...
@@ -198,7 +185,14 @@ func GetClientFromCache(user *model.User, asset *model.Asset, systemUser *model.
if
!
ok
{
if
!
ok
{
return
return
}
}
var
u
=
user
.
Username
var
ip
=
asset
.
IP
var
sysName
=
systemUser
.
Username
clientsRefCounter
[
client
]
++
clientsRefCounter
[
client
]
++
var
counter
=
clientsRefCounter
[
client
]
logger
.
Infof
(
"Reuse connection: %s->%s@%s ref: %d"
,
u
,
sysName
,
ip
,
counter
)
return
return
}
}
...
...
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