mirror of
https://github.com/ipfs/kubo.git
synced 2025-09-10 14:34:24 +08:00
fix(core) check nil for _all_ owned resources
since construction can fail, and construction is non-trivial, it's probably safer to never assume resource exists. cc @jbenet @whyrusleeping
This commit is contained in:
@ -280,17 +280,16 @@ func (n *IpfsNode) teardown() error {
|
|||||||
log.Debug("core is shutting down...")
|
log.Debug("core is shutting down...")
|
||||||
// owned objects are closed in this teardown to ensure that they're closed
|
// owned objects are closed in this teardown to ensure that they're closed
|
||||||
// regardless of which constructor was used to add them to the node.
|
// regardless of which constructor was used to add them to the node.
|
||||||
closers := []io.Closer{
|
var closers []io.Closer
|
||||||
n.Blocks,
|
|
||||||
n.Exchange,
|
|
||||||
n.Repo,
|
|
||||||
}
|
|
||||||
addCloser := func(c io.Closer) { // use when field may be nil
|
addCloser := func(c io.Closer) { // use when field may be nil
|
||||||
if c != nil {
|
if c != nil {
|
||||||
closers = append(closers, c)
|
closers = append(closers, c)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
addCloser(n.Blocks)
|
||||||
|
addCloser(n.Exchange)
|
||||||
|
addCloser(n.Repo)
|
||||||
addCloser(n.Bootstrapper)
|
addCloser(n.Bootstrapper)
|
||||||
if dht, ok := n.Routing.(*dht.IpfsDHT); ok {
|
if dht, ok := n.Routing.(*dht.IpfsDHT); ok {
|
||||||
addCloser(dht)
|
addCloser(dht)
|
||||||
|
Reference in New Issue
Block a user