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
95b5ad37
Commit
95b5ad37
authored
5 years ago
by
Xin.Zh
Committed by
GitHub
5 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #106 from fangyincheng/services
Fix:Lock bug
parents
36c78543
1369c1ef
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
protocol/dubbo/client.go
+6
-18
6 additions, 18 deletions
protocol/dubbo/client.go
protocol/dubbo/codec.go
+3
-3
3 additions, 3 deletions
protocol/dubbo/codec.go
protocol/dubbo/readwriter.go
+0
-2
0 additions, 2 deletions
protocol/dubbo/readwriter.go
with
9 additions
and
23 deletions
protocol/dubbo/client.go
+
6
−
18
View file @
95b5ad37
...
...
@@ -148,14 +148,13 @@ type Client struct {
pool
*
gettyRPCClientPool
sequence
atomic
.
Uint64
pendingLock
sync
.
RWMutex
pendingResponses
map
[
SequenceType
]
*
PendingResponse
pendingResponses
*
sync
.
Map
}
func
NewClient
()
*
Client
{
c
:=
&
Client
{
pendingResponses
:
make
(
map
[
SequenceType
]
*
PendingResponse
),
pendingResponses
:
new
(
sync
.
Map
),
conf
:
*
clientConf
,
}
c
.
pool
=
newGettyRPCClientConnPool
(
c
,
clientConf
.
PoolSize
,
time
.
Duration
(
int
(
time
.
Second
)
*
clientConf
.
PoolTTL
))
...
...
@@ -201,13 +200,6 @@ func (c *Client) AsyncCall(addr string, svcUrl common.URL, method string, args i
return
perrors
.
WithStack
(
c
.
call
(
CT_TwoWay
,
addr
,
svcUrl
,
method
,
args
,
reply
,
callback
,
copts
))
}
func
(
c
*
Client
)
GetPendingResponse
(
seq
SequenceType
)
*
PendingResponse
{
c
.
pendingLock
.
RLock
()
defer
c
.
pendingLock
.
RUnlock
()
return
c
.
pendingResponses
[
SequenceType
(
seq
)]
}
func
(
c
*
Client
)
call
(
ct
CallType
,
addr
string
,
svcUrl
common
.
URL
,
method
string
,
args
,
reply
interface
{},
callback
AsyncCallback
,
opts
CallOptions
)
error
{
...
...
@@ -330,20 +322,16 @@ func (c *Client) transfer(session getty.Session, pkg *DubboPackage,
}
func
(
c
*
Client
)
addPendingResponse
(
pr
*
PendingResponse
)
{
c
.
pendingLock
.
Lock
()
defer
c
.
pendingLock
.
Unlock
()
c
.
pendingResponses
[
SequenceType
(
pr
.
seq
)]
=
pr
c
.
pendingResponses
.
Store
(
SequenceType
(
pr
.
seq
),
pr
)
}
func
(
c
*
Client
)
removePendingResponse
(
seq
SequenceType
)
*
PendingResponse
{
c
.
pendingLock
.
Lock
()
defer
c
.
pendingLock
.
Unlock
()
if
c
.
pendingResponses
==
nil
{
return
nil
}
if
presp
,
ok
:=
c
.
pendingResponses
[
seq
]
;
ok
{
delete
(
c
.
pendingResponses
,
seq
)
return
presp
if
presp
,
ok
:=
c
.
pendingResponses
.
Load
(
seq
)
;
ok
{
c
.
pendingResponses
.
Delete
(
seq
)
return
presp
.
(
*
PendingResponse
)
}
return
nil
}
This diff is collapsed.
Click to expand it.
protocol/dubbo/codec.go
+
3
−
3
View file @
95b5ad37
...
...
@@ -88,11 +88,11 @@ func (p *DubboPackage) Unmarshal(buf *bytes.Buffer, opts ...interface{}) error {
return
perrors
.
Errorf
(
"opts[0] is not of type *Client"
)
}
pendingRsp
:=
client
.
GetP
endingResponse
(
SequenceType
(
p
.
Header
.
ID
))
if
pendingRsp
==
nil
{
pendingRsp
,
ok
:=
client
.
p
endingResponse
s
.
Load
(
SequenceType
(
p
.
Header
.
ID
))
if
!
ok
{
return
perrors
.
Errorf
(
"client.GetPendingResponse(%v) = nil"
,
p
.
Header
.
ID
)
}
else
{
p
.
Body
=
&
hessian
.
Response
{
RspObj
:
pendingRsp
.
reply
}
p
.
Body
=
&
hessian
.
Response
{
RspObj
:
pendingRsp
.
(
*
PendingResponse
)
.
reply
}
}
}
...
...
This diff is collapsed.
Click to expand it.
protocol/dubbo/readwriter.go
+
0
−
2
View file @
95b5ad37
...
...
@@ -46,8 +46,6 @@ func NewRpcClientPackageHandler(client *Client) *RpcClientPackageHandler {
}
func
(
p
*
RpcClientPackageHandler
)
Read
(
ss
getty
.
Session
,
data
[]
byte
)
(
interface
{},
int
,
error
)
{
p
.
client
.
pendingLock
.
RLock
()
defer
p
.
client
.
pendingLock
.
RUnlock
()
pkg
:=
&
DubboPackage
{}
buf
:=
bytes
.
NewBuffer
(
data
)
...
...
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