Skip to content

Commit

Permalink
try not to leak
Browse files Browse the repository at this point in the history
  • Loading branch information
djdv committed Oct 25, 2019
1 parent 984f155 commit 0fa5983
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 8 deletions.
8 changes: 0 additions & 8 deletions plugin/plugins/filesystem/nodes/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,15 +144,7 @@ func (ib *IPFSBase) close() error {
}

if ib.filesystemCancel != nil {
/* TODO: only do this on the last close to the root
if ib.proxy != nil {
if err := ib.proxy.Close(); err != nil {
ib.Logger.Error(err)
}
lastErr = err
}
ib.filesystemCancel()
*/
}

if ib.operationsCancel != nil {
Expand Down
6 changes: 6 additions & 0 deletions plugin/plugins/filesystem/nodes/keyfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package fsnodes

import (
"context"
"runtime"

"github.com/hugelgupf/p9/p9"
"github.com/hugelgupf/p9/unimplfs"
Expand Down Expand Up @@ -39,6 +40,11 @@ func KeyFSAttacher(ctx context.Context, core coreiface.CoreAPI, ops ...nodeopts.

kd.proxy = subsystem.(fsutils.WalkRef)

// detach from our proxied system when we fall out of memory
runtime.SetFinalizer(kd, func(keyRoot *KeyFS) {
keyRoot.proxy.Close()
})

return kd
}

Expand Down
6 changes: 6 additions & 0 deletions plugin/plugins/filesystem/nodes/pinfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
gopath "path"
"runtime"

"github.com/hugelgupf/p9/p9"
"github.com/hugelgupf/p9/unimplfs"
Expand Down Expand Up @@ -43,6 +44,11 @@ func PinFSAttacher(ctx context.Context, core coreiface.CoreAPI, ops ...nodeopts.

pd.proxy = subsystem.(fsutils.WalkRef)

// detach from our proxied system when we fall out of memory
runtime.SetFinalizer(pd, func(pinRoot *PinFS) {
pinRoot.proxy.Close()
})

return pd
}

Expand Down
8 changes: 8 additions & 0 deletions plugin/plugins/filesystem/nodes/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package fsnodes

import (
"context"
"runtime"

"github.com/hugelgupf/p9/p9"
"github.com/hugelgupf/p9/unimplfs"
Expand Down Expand Up @@ -116,6 +117,13 @@ func RootAttacher(ctx context.Context, core coreiface.CoreAPI, ops ...nodeopts.A
}
}

// detach from our proxied systems when we fall out of memory
runtime.SetFinalizer(ri, func(root *RootIndex) {
for _, ss := range ri.subsystems {
ss.file.Close()
}
})

return ri
}

Expand Down

0 comments on commit 0fa5983

Please sign in to comment.