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
dms3
go-bitswap
Commits
51e82a65
Commit
51e82a65
authored
Feb 04, 2019
by
hannahhoward
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(providerquerymanager): minor fixes to capture all cancellations
parent
92717dbb
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
12 deletions
+24
-12
providerquerymanager/providerquerymanager.go
providerquerymanager/providerquerymanager.go
+24
-12
No files found.
providerquerymanager/providerquerymanager.go
View file @
51e82a65
...
...
@@ -124,6 +124,8 @@ func (pqm *ProviderQueryManager) FindProvidersAsync(sessionCtx context.Context,
var
receivedInProgressRequest
inProgressRequest
select
{
case
<-
pqm
.
ctx
.
Done
()
:
return
nil
case
<-
sessionCtx
.
Done
()
:
return
nil
case
receivedInProgressRequest
=
<-
inProgressRequestChan
:
...
...
@@ -158,15 +160,25 @@ func (pqm *ProviderQueryManager) receiveProviders(sessionCtx context.Context, k
}
for
len
(
receivedProviders
)
>
0
||
incomingProviders
!=
nil
{
select
{
case
<-
pqm
.
ctx
.
Done
()
:
return
case
<-
sessionCtx
.
Done
()
:
pqm
.
providerQueryMessages
<-
&
cancelRequestMessage
{
incomingProviders
:
incomingProviders
,
k
:
k
,
}
// clear out any remaining providers
for
range
incomingProviders
{
// clear out any remaining providers, in case and "incoming provider"
// messages get processed before our cancel message
for
{
select
{
case
_
,
ok
:=
<-
incomingProviders
:
if
!
ok
{
return
}
case
<-
pqm
.
ctx
.
Done
()
:
return
}
}
return
case
provider
,
ok
:=
<-
incomingProviders
:
if
!
ok
{
incomingProviders
=
nil
...
...
@@ -362,15 +374,15 @@ func (crm *cancelRequestMessage) debugMessage() string {
func
(
crm
*
cancelRequestMessage
)
handle
(
pqm
*
ProviderQueryManager
)
{
requestStatus
,
ok
:=
pqm
.
inProgressRequestStatuses
[
crm
.
k
]
if
!
ok
{
if
ok
{
_
,
ok
:=
requestStatus
.
listeners
[
crm
.
incomingProviders
]
if
ok
{
delete
(
requestStatus
.
listeners
,
crm
.
incomingProviders
)
}
else
{
log
.
Errorf
(
"Attempt to cancel request for for cid (%s) this is not a listener"
,
crm
.
k
.
String
())
}
}
else
{
log
.
Errorf
(
"Attempt to cancel request for cid (%s) not in progress"
,
crm
.
k
.
String
())
return
}
listener
:=
crm
.
incomingProviders
if
!
ok
{
log
.
Errorf
(
"Attempt to cancel request for for cid (%s) this is not a listener"
,
crm
.
k
.
String
())
return
}
close
(
listener
)
delete
(
requestStatus
.
listeners
,
listener
)
close
(
crm
.
incomingProviders
)
}
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