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
Commits
e0f38fa3
Unverified
Commit
e0f38fa3
authored
Nov 21, 2017
by
Whyrusleeping
Committed by
GitHub
Nov 21, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #4406 from ipfs/fix/4405
Fix two race conditions (and possibly go routine leaks) in commands
parents
33c82070
d89a4b69
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
15 deletions
+18
-15
core/commands/add.go
core/commands/add.go
+8
-4
core/commands/pin.go
core/commands/pin.go
+10
-11
No files found.
core/commands/add.go
View file @
e0f38fa3
...
...
@@ -342,6 +342,8 @@ You can now check what blocks have been created by:
},
PostRun
:
map
[
cmds
.
EncodingType
]
func
(
cmds
.
Request
,
cmds
.
ResponseEmitter
)
cmds
.
ResponseEmitter
{
cmds
.
CLI
:
func
(
req
cmds
.
Request
,
re
cmds
.
ResponseEmitter
)
cmds
.
ResponseEmitter
{
ctx
:=
req
.
Context
()
reNext
,
res
:=
cmds
.
NewChanResponsePair
(
req
)
outChan
:=
make
(
chan
interface
{})
...
...
@@ -429,9 +431,6 @@ You can now check what blocks have been created by:
bar
.
ShowBar
=
true
bar
.
ShowTimeLeft
=
true
}
case
<-
req
.
Context
()
.
Done
()
:
re
.
SetError
(
req
.
Context
()
.
Err
(),
cmdkit
.
ErrNormal
)
return
}
}
}
...
...
@@ -469,7 +468,12 @@ You can now check what blocks have been created by:
return
}
outChan
<-
v
select
{
case
outChan
<-
v
:
case
<-
ctx
.
Done
()
:
re
.
SetError
(
ctx
.
Err
(),
cmdkit
.
ErrNormal
)
return
}
}
}()
...
...
core/commands/pin.go
View file @
e0f38fa3
...
...
@@ -90,15 +90,14 @@ var addPinCmd = &cmds.Command{
v
:=
new
(
dag
.
ProgressTracker
)
ctx
:=
v
.
DeriveContext
(
req
.
Context
())
ch
:=
make
(
chan
[]
*
cid
.
Cid
)
type
pinResult
struct
{
pins
[]
*
cid
.
Cid
err
error
}
ch
:=
make
(
chan
pinResult
,
1
)
go
func
()
{
defer
close
(
ch
)
added
,
err
:=
corerepo
.
Pin
(
n
,
ctx
,
req
.
Arguments
(),
recursive
)
if
err
!=
nil
{
res
.
SetError
(
err
,
cmdkit
.
ErrNormal
)
return
}
ch
<-
added
ch
<-
pinResult
{
pins
:
added
,
err
:
err
}
}()
ticker
:=
time
.
NewTicker
(
500
*
time
.
Millisecond
)
...
...
@@ -106,16 +105,16 @@ var addPinCmd = &cmds.Command{
defer
close
(
out
)
for
{
select
{
case
val
,
ok
:=
<-
ch
:
if
!
ok
{
// error already set just return
case
val
:=
<-
ch
:
if
val
.
err
!=
nil
{
res
.
SetError
(
val
.
err
,
cmdkit
.
ErrNormal
)
return
}
if
pv
:=
v
.
Value
();
pv
!=
0
{
out
<-
&
AddPinOutput
{
Progress
:
v
.
Value
()}
}
out
<-
&
AddPinOutput
{
Pins
:
cidsToStrings
(
val
)}
out
<-
&
AddPinOutput
{
Pins
:
cidsToStrings
(
val
.
pins
)}
return
case
<-
ticker
.
C
:
out
<-
&
AddPinOutput
{
Progress
:
v
.
Value
()}
...
...
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