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
a23f85a4
Commit
a23f85a4
authored
5 years ago
by
vito.he
Committed by
GitHub
5 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #190 from divebomb/develop
Imp: remove client from pool before closing it
parents
5a86ae83
245c0afc
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
protocol/dubbo/pool.go
+13
-12
13 additions, 12 deletions
protocol/dubbo/pool.go
with
13 additions
and
12 deletions
protocol/dubbo/pool.go
+
13
−
12
View file @
a23f85a4
...
...
@@ -39,7 +39,7 @@ type gettyRPCClient struct {
once
sync
.
Once
protocol
string
addr
string
created
int64
// zero, not create or be destroyed
active
int64
// zero, not create or be destroyed
pool
*
gettyRPCClientPool
...
...
@@ -85,11 +85,11 @@ func newGettyRPCClientConn(pool *gettyRPCClientPool, protocol, addr string) (*ge
}
func
(
c
*
gettyRPCClient
)
updateActive
(
active
int64
)
{
atomic
.
StoreInt64
(
&
c
.
created
,
active
)
atomic
.
StoreInt64
(
&
c
.
active
,
active
)
}
func
(
c
*
gettyRPCClient
)
getActive
()
int64
{
return
atomic
.
LoadInt64
(
&
c
.
created
)
return
atomic
.
LoadInt64
(
&
c
.
active
)
}
func
(
c
*
gettyRPCClient
)
newSession
(
session
getty
.
Session
)
error
{
...
...
@@ -154,6 +154,9 @@ func (c *gettyRPCClient) addSession(session getty.Session) {
}
c
.
lock
.
Lock
()
if
c
.
sessions
==
nil
{
c
.
sessions
=
make
([]
*
rpcSession
,
0
,
16
)
}
c
.
sessions
=
append
(
c
.
sessions
,
&
rpcSession
{
session
:
session
})
c
.
lock
.
Unlock
()
}
...
...
@@ -271,7 +274,7 @@ func newGettyRPCClientConnPool(rpcClient *Client, size int, ttl time.Duration) *
rpcClient
:
rpcClient
,
size
:
size
,
ttl
:
int64
(
ttl
.
Seconds
()),
conns
:
[]
*
gettyRPCClient
{}
,
conns
:
make
(
[]
*
gettyRPCClient
,
0
,
16
)
,
}
}
...
...
@@ -300,12 +303,11 @@ func (p *gettyRPCClientPool) getGettyRpcClient(protocol, addr string) (*gettyRPC
p
.
conns
=
p
.
conns
[
:
len
(
p
.
conns
)
-
1
]
if
d
:=
now
-
conn
.
getActive
();
d
>
p
.
ttl
{
if
closeErr
:=
conn
.
safeClose
();
closeErr
==
nil
{
p
.
remove
(
conn
)
}
p
.
remove
(
conn
)
conn
.
safeClose
()
continue
}
conn
.
updateActive
(
now
)
//update
created
time
conn
.
updateActive
(
now
)
//update
active
time
return
conn
,
nil
}
...
...
@@ -331,10 +333,9 @@ func (p *gettyRPCClientPool) release(conn *gettyRPCClient, err error) {
}
if
len
(
p
.
conns
)
>=
p
.
size
{
if
closeErr
:=
conn
.
safeClose
();
closeErr
==
nil
{
// delete @conn from client pool
p
.
remove
(
conn
)
}
// delete @conn from client pool
p
.
remove
(
conn
)
conn
.
safeClose
()
return
}
p
.
conns
=
append
(
p
.
conns
,
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