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-dms3-provider
Commits
184f9bd2
Unverified
Commit
184f9bd2
authored
Mar 11, 2020
by
Steven Allen
Committed by
GitHub
Mar 11, 2020
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #22 from ipfs/fix/bugs
Fix several race on close bugs
parents
e52462ce
c835ad80
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
10 deletions
+17
-10
queue/queue.go
queue/queue.go
+17
-10
No files found.
queue/queue.go
View file @
184f9bd2
...
...
@@ -56,10 +56,12 @@ func (q *Queue) Close() error {
}
// Enqueue puts a cid in the queue
func
(
q
*
Queue
)
Enqueue
(
cid
cid
.
Cid
)
{
func
(
q
*
Queue
)
Enqueue
(
cid
cid
.
Cid
)
error
{
select
{
case
q
.
enqueue
<-
cid
:
return
nil
case
<-
q
.
ctx
.
Done
()
:
return
fmt
.
Errorf
(
"failed to enqueue CID: shutting down"
)
}
}
...
...
@@ -75,22 +77,27 @@ func (q *Queue) work() {
var
c
cid
.
Cid
=
cid
.
Undef
defer
func
()
{
// also cancels any in-progess enqueue tasks.
q
.
close
()
// unblocks anyone waiting
close
(
q
.
dequeue
)
// unblocks the close call
close
(
q
.
closed
)
}()
for
{
if
c
==
cid
.
Undef
{
head
,
e
:=
q
.
getQueueHead
()
head
,
e
rr
:=
q
.
getQueueHead
()
if
e
!=
nil
{
log
.
Errorf
(
"error querying for head of queue: %s, stopping provider"
,
e
)
if
e
rr
!=
nil
{
log
.
Errorf
(
"error querying for head of queue: %s, stopping provider"
,
e
rr
)
return
}
else
if
head
!=
nil
{
k
=
datastore
.
NewKey
(
head
.
Key
)
c
,
e
=
cid
.
Parse
(
head
.
Value
)
if
e
!=
nil
{
log
.
Warningf
(
"error parsing queue entry cid with key (%s), removing it from queue: %s"
,
head
.
Key
,
e
)
err
:
=
q
.
ds
.
Delete
(
k
)
c
,
e
rr
=
cid
.
Parse
(
head
.
Value
)
if
e
rr
!=
nil
{
log
.
Warningf
(
"error parsing queue entry cid with key (%s), removing it from queue: %s"
,
head
.
Key
,
e
rr
)
err
=
q
.
ds
.
Delete
(
k
)
if
err
!=
nil
{
log
.
Errorf
(
"error deleting queue entry with key (%s), due to error (%s), stopping provider"
,
head
.
Key
,
err
)
return
...
...
@@ -132,7 +139,7 @@ func (q *Queue) work() {
}()
}
func
(
q
*
Queue
)
getQueueHead
()
(
*
query
.
Result
,
error
)
{
func
(
q
*
Queue
)
getQueueHead
()
(
*
query
.
Entry
,
error
)
{
qry
:=
query
.
Query
{
Orders
:
[]
query
.
Order
{
query
.
OrderByKey
{}},
Limit
:
1
}
results
,
err
:=
q
.
ds
.
Query
(
qry
)
if
err
!=
nil
{
...
...
@@ -144,5 +151,5 @@ func (q *Queue) getQueueHead() (*query.Result, error) {
return
nil
,
nil
}
return
&
r
,
nil
return
&
r
.
Entry
,
r
.
Error
}
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