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
8c252932
Unverified
Commit
8c252932
authored
Sep 16, 2019
by
Eric_Lee
Committed by
GitHub
Sep 16, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修复网域连接关闭 (#83)
parent
b991c052
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
9 deletions
+21
-9
connmanager.go
pkg/srvconn/connmanager.go
+21
-9
No files found.
pkg/srvconn/connmanager.go
View file @
8c252932
...
...
@@ -31,8 +31,9 @@ var (
)
type
SSHClient
struct
{
client
*
gossh
.
Client
username
string
client
*
gossh
.
Client
proxyConn
gossh
.
Conn
username
string
ref
int
key
string
...
...
@@ -79,6 +80,9 @@ func (s *SSHClient) Close() error {
default
:
close
(
s
.
closed
)
}
if
s
.
proxyConn
!=
nil
{
_
=
s
.
proxyConn
.
Close
()
}
s
.
mu
.
Lock
()
s
.
ref
=
0
s
.
mu
.
Unlock
()
...
...
@@ -254,10 +258,11 @@ func newClient(asset *model.Asset, systemUser *model.SystemUser, timeout time.Du
return
nil
,
err
}
closed
:=
make
(
chan
struct
{})
client
=
&
SSHClient
{
client
:
conn
,
username
:
systemUser
.
Username
,
mu
:
new
(
sync
.
RWMutex
),
ref
:
1
,
closed
:
closed
}
client
=
&
SSHClient
{
client
:
conn
,
proxyConn
:
sshConfig
.
proxyConn
,
username
:
systemUser
.
Username
,
mu
:
new
(
sync
.
RWMutex
),
ref
:
1
,
closed
:
closed
}
go
KeepAlive
(
client
,
closed
,
60
)
return
client
,
nil
}
...
...
@@ -298,8 +303,15 @@ func getClientFromCache(key string) (client *SSHClient) {
func
setClientCache
(
key
string
,
client
*
SSHClient
)
{
clientLock
.
Lock
()
sshClients
[
key
]
=
client
client
.
key
=
key
if
_
,
ok
:=
sshClients
[
key
];
!
ok
{
sshClients
[
key
]
=
client
client
.
key
=
key
}
else
{
newKey
:=
fmt
.
Sprintf
(
"%s_%s"
,
key
,
time
.
Now
()
.
UTC
()
.
Format
(
"20060102150405"
))
sshClients
[
newKey
]
=
client
client
.
key
=
newKey
logger
.
Debugf
(
"SSH Client key already used, use new key"
)
}
clientLock
.
Unlock
()
}
...
...
@@ -319,7 +331,7 @@ func RecycleClient(client *SSHClient) {
}
else
{
logger
.
Infof
(
"Close ssh client %p"
,
client
)
}
}
else
{
}
else
{
logger
.
Debugf
(
"SSH client %p ref -1, current ref: %s"
,
client
,
client
.
refCount
())
}
}
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