Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
2
22a7f0099
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Summer2022
22a7f0099
Commits
fe3c5b04
Commit
fe3c5b04
authored
5 years ago
by
cvictory
Browse files
Options
Downloads
Patches
Plain Diff
fix issue: create gettyClientConn every time
parent
dc2b68f2
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
remoting/getty/pool.go
+14
-10
14 additions, 10 deletions
remoting/getty/pool.go
with
14 additions
and
10 deletions
remoting/getty/pool.go
+
14
−
10
View file @
fe3c5b04
...
...
@@ -98,7 +98,6 @@ func (c *gettyRPCClient) newSession(session getty.Session) error {
tcpConn
*
net
.
TCPConn
conf
ClientConfig
)
conf
=
c
.
pool
.
rpcClient
.
conf
if
conf
.
GettySessionParam
.
CompressEncoding
{
session
.
SetCompressType
(
getty
.
CompressZip
)
...
...
@@ -301,7 +300,8 @@ func newGettyRPCClientConnPool(rpcClient *Client, size int, ttl time.Duration) *
rpcClient
:
rpcClient
,
size
:
size
,
ttl
:
int64
(
ttl
.
Seconds
()),
conns
:
make
([]
*
gettyRPCClient
,
0
,
16
),
// init capacity : 2
conns
:
make
([]
*
gettyRPCClient
,
0
,
2
),
}
}
...
...
@@ -320,6 +320,9 @@ func (p *gettyRPCClientPool) getGettyRpcClient(addr string) (*gettyRPCClient, er
if
err
==
nil
&&
conn
==
nil
{
// create new conn
rpcClientConn
,
err
:=
newGettyRPCClientConn
(
p
,
addr
)
if
err
==
nil
{
p
.
put
(
rpcClientConn
)
}
return
rpcClientConn
,
perrors
.
WithStack
(
err
)
}
return
conn
,
perrors
.
WithStack
(
err
)
...
...
@@ -333,10 +336,15 @@ func (p *gettyRPCClientPool) get() (*gettyRPCClient, error) {
if
p
.
conns
==
nil
{
return
nil
,
errClientPoolClosed
}
for
len
(
p
.
conns
)
>
0
{
conn
:=
p
.
conns
[
len
(
p
.
conns
)
-
1
]
p
.
conns
=
p
.
conns
[
:
len
(
p
.
conns
)
-
1
]
for
num
:=
len
(
p
.
conns
);
num
>
0
;
{
var
conn
*
gettyRPCClient
if
num
!=
1
{
conn
=
p
.
conns
[
rand
.
Int31n
(
int32
(
num
))]
}
else
{
conn
=
p
.
conns
[
0
]
}
// This will recreate gettyRpcClient for remove last position
//p.conns = p.conns[:len(p.conns)-1]
if
d
:=
now
-
conn
.
getActive
();
d
>
p
.
ttl
{
p
.
remove
(
conn
)
...
...
@@ -353,21 +361,17 @@ func (p *gettyRPCClientPool) put(conn *gettyRPCClient) {
if
conn
==
nil
||
conn
.
getActive
()
==
0
{
return
}
p
.
Lock
()
defer
p
.
Unlock
()
if
p
.
conns
==
nil
{
return
}
// check whether @conn has existed in p.conns or not.
for
i
:=
range
p
.
conns
{
if
p
.
conns
[
i
]
==
conn
{
return
}
}
if
len
(
p
.
conns
)
>=
p
.
size
{
// delete @conn from client pool
// p.remove(conn)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment