mirror of
https://github.com/ipfs/kubo.git
synced 2025-07-01 10:49:24 +08:00
fix concurrent SetError in add command
I believe this also fixes a potential go routine leak (on race). License: MIT Signed-off-by: Steven Allen <steven@stebalien.com>
This commit is contained in:
@ -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{
|
PostRun: map[cmds.EncodingType]func(cmds.Request, cmds.ResponseEmitter) cmds.ResponseEmitter{
|
||||||
cmds.CLI: func(req cmds.Request, re cmds.ResponseEmitter) cmds.ResponseEmitter {
|
cmds.CLI: func(req cmds.Request, re cmds.ResponseEmitter) cmds.ResponseEmitter {
|
||||||
|
ctx := req.Context()
|
||||||
|
|
||||||
reNext, res := cmds.NewChanResponsePair(req)
|
reNext, res := cmds.NewChanResponsePair(req)
|
||||||
outChan := make(chan interface{})
|
outChan := make(chan interface{})
|
||||||
|
|
||||||
@ -429,9 +431,6 @@ You can now check what blocks have been created by:
|
|||||||
bar.ShowBar = true
|
bar.ShowBar = true
|
||||||
bar.ShowTimeLeft = 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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
outChan <- v
|
select {
|
||||||
|
case outChan <- v:
|
||||||
|
case <-ctx.Done():
|
||||||
|
re.SetError(ctx.Err(), cmdkit.ErrNormal)
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user