Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
p2p
go-p2p-pubsub
Commits
9a0bd7ad
Commit
9a0bd7ad
authored
May 01, 2020
by
Lukasz Zimnoch
Committed by
vyzo
May 01, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Prevent multiple invocations of relay cancel function
parent
9a0d2f59
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
1 deletion
+24
-1
pubsub.go
pubsub.go
+11
-1
topic_test.go
topic_test.go
+13
-0
No files found.
pubsub.go
View file @
9a0bd7ad
...
...
@@ -676,12 +676,22 @@ func (p *PubSub) handleAddRelay(req *addRelayReq) {
p
.
rt
.
Join
(
topic
)
}
req
.
resp
<-
func
()
{
// flag used to prevent calling cancel function multiple times
isCancelled
:=
false
relayCancelFunc
:=
func
()
{
if
isCancelled
{
return
}
select
{
case
p
.
rmRelay
<-
topic
:
isCancelled
=
true
case
<-
p
.
ctx
.
Done
()
:
}
}
req
.
resp
<-
relayCancelFunc
}
// handleRemoveRelay removes one relay reference from bookkeeping.
...
...
topic_test.go
View file @
9a0bd7ad
...
...
@@ -629,7 +629,20 @@ func TestTopicRelayReuse(t *testing.T) {
t
.
Fatal
(
"incorrect number of relays"
)
}
// only the first invocation should take effect
relay1Cancel
()
relay1Cancel
()
relay1Cancel
()
pubsubs
[
0
]
.
eval
<-
func
()
{
res
<-
pubsubs
[
0
]
.
myRelays
[
topic
]
==
2
}
isCorrectNumber
=
<-
res
if
!
isCorrectNumber
{
t
.
Fatal
(
"incorrect number of relays"
)
}
relay2Cancel
()
relay3Cancel
()
...
...
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