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-graphsync
Commits
29acd2c0
Unverified
Commit
29acd2c0
authored
Sep 17, 2020
by
Aarsh Shah
Committed by
GitHub
Sep 17, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Return Request context cancelled error (#93)
* request context cancelled error
parent
d88611c4
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
1 deletion
+27
-1
graphsync.go
graphsync.go
+7
-0
requestmanager/requestmanager_test.go
requestmanager/requestmanager_test.go
+6
-1
requestmanager/responsecollector.go
requestmanager/responsecollector.go
+14
-0
No files found.
graphsync.go
View file @
29acd2c0
...
@@ -94,6 +94,13 @@ const (
...
@@ -94,6 +94,13 @@ const (
RequestCancelled
=
ResponseStatusCode
(
35
)
RequestCancelled
=
ResponseStatusCode
(
35
)
)
)
// RequestContextCancelledErr is an error message received on the error channel when the request context given by the user is cancelled/times out
type
RequestContextCancelledErr
struct
{}
func
(
e
RequestContextCancelledErr
)
Error
()
string
{
return
"Request Context Cancelled"
}
// RequestFailedBusyErr is an error message received on the error channel when the peer is busy
// RequestFailedBusyErr is an error message received on the error channel when the peer is busy
type
RequestFailedBusyErr
struct
{}
type
RequestFailedBusyErr
struct
{}
...
...
requestmanager/requestmanager_test.go
View file @
29acd2c0
...
@@ -199,8 +199,13 @@ func TestCancelRequestInProgress(t *testing.T) {
...
@@ -199,8 +199,13 @@ func TestCancelRequestInProgress(t *testing.T) {
testutil
.
VerifyEmptyResponse
(
requestCtx
,
t
,
returnedResponseChan1
)
testutil
.
VerifyEmptyResponse
(
requestCtx
,
t
,
returnedResponseChan1
)
td
.
blockChain
.
VerifyWholeChain
(
requestCtx
,
returnedResponseChan2
)
td
.
blockChain
.
VerifyWholeChain
(
requestCtx
,
returnedResponseChan2
)
testutil
.
VerifyEmptyErrors
(
requestCtx
,
t
,
returnedErrorChan1
)
testutil
.
VerifyEmptyErrors
(
requestCtx
,
t
,
returnedErrorChan2
)
testutil
.
VerifyEmptyErrors
(
requestCtx
,
t
,
returnedErrorChan2
)
errors
:=
testutil
.
CollectErrors
(
requestCtx
,
t
,
returnedErrorChan1
)
require
.
Len
(
t
,
errors
,
1
)
_
,
ok
:=
errors
[
0
]
.
(
graphsync
.
RequestContextCancelledErr
)
require
.
True
(
t
,
ok
)
}
}
func
TestCancelManagerExitsGracefully
(
t
*
testing
.
T
)
{
func
TestCancelManagerExitsGracefully
(
t
*
testing
.
T
)
{
...
...
requestmanager/responsecollector.go
View file @
29acd2c0
...
@@ -80,10 +80,24 @@ func (rc *responseCollector) collectResponses(
...
@@ -80,10 +80,24 @@ func (rc *responseCollector) collectResponses(
case
<-
rc
.
ctx
.
Done
()
:
case
<-
rc
.
ctx
.
Done
()
:
return
return
case
<-
requestCtx
.
Done
()
:
case
<-
requestCtx
.
Done
()
:
select
{
case
<-
rc
.
ctx
.
Done
()
:
case
returnedErrors
<-
graphsync
.
RequestContextCancelledErr
{}
:
}
return
return
case
err
,
ok
:=
<-
incomingErrors
:
case
err
,
ok
:=
<-
incomingErrors
:
if
!
ok
{
if
!
ok
{
incomingErrors
=
nil
incomingErrors
=
nil
// even if the `incomingErrors` channel is closed without any error,
// the context could still have timed out in which case we need to inform the caller of the same.
select
{
case
<-
requestCtx
.
Done
()
:
select
{
case
<-
rc
.
ctx
.
Done
()
:
case
returnedErrors
<-
graphsync
.
RequestContextCancelledErr
{}
:
}
default
:
}
}
else
{
}
else
{
receivedErrors
=
append
(
receivedErrors
,
err
)
receivedErrors
=
append
(
receivedErrors
,
err
)
}
}
...
...
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