@cryptotaxi247 / kubo / commits / f26388e0e

fix(core) tear-down leveldb

@jbenet @whyrusleeping @mappum If we permit initialization in `ipfs daemon`, then we must ensure that the node instantiated in `ipfs init` (to create the welcome file) shuts down and releases resources. Kept running into "resource temporarily unavailable". Discovered that it was our cousins Jeff and Sanjay over at LevelDB Ave. go-datastore doesn't expose Close() so I extended the TsDs interface and submitted a patch. License: MIT Signed-off-by: Brian Tiger Chow <brian@perfmode.com> Signed-off-by: Brian Tiger Chow <brian.holderchow@gmail.com>

Brian Tiger Chow committed Nov 16, 2014 at 11:46 UTC f26388e0e587c85ea36a11250f0ecb48250e64b6
2 files changed +8 -3
core/core.go
+6 -1
@@ -48,7 +48,7 @@ type IpfsNode struct {
48 Peerstore peer.Peerstore
49
50 // the local datastore
51 - Datastore ds.ThreadSafeDatastore
51 + Datastore ds.ThreadSafeDatastoreCloser
52
53 // the network message stream
54 Network inet.Network
@@ -192,6 +192,11 @@ func NewIpfsNode(cfg *config.Config, online bool) (n *IpfsNode, err error) {
192 return n, nil
193 }
194
195 +func (n *IpfsNode) Close() {
196 + n.ContextCloser.Close()
197 + n.Datastore.Close()
198 +}
199 +
200 func (n *IpfsNode) OnlineMode() bool {
201 return n.onlineMode
202 }
core/datastore.go
+2 -2
@@ -14,7 +14,7 @@ import (
14 u "github.com/jbenet/go-ipfs/util"
15 )
16
17 -func makeDatastore(cfg config.Datastore) (ds.ThreadSafeDatastore, error) {
17 +func makeDatastore(cfg config.Datastore) (ds.ThreadSafeDatastoreCloser, error) {
18 if len(cfg.Type) == 0 {
19 return nil, fmt.Errorf("config datastore.type required")
20 }
@@ -39,7 +39,7 @@ func makeDatastore(cfg config.Datastore) (ds.ThreadSafeDatastore, error) {
39 return nil, fmt.Errorf("Unknown datastore type: %s", cfg.Type)
40 }
41
42 -func makeLevelDBDatastore(cfg config.Datastore) (ds.ThreadSafeDatastore, error) {
42 +func makeLevelDBDatastore(cfg config.Datastore) (ds.ThreadSafeDatastoreCloser, error) {
43 if len(cfg.Path) == 0 {
44 return nil, fmt.Errorf("config datastore.path required for leveldb")
45 }