Routing none: provider keystore datastore is never closed, so reopening the repo in the same process fails
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 68/100
Research direction
Start in core/node/provider.go, in SweepingProviderOpt, where the ResettableKeystore is created before the nil-DHT check that returns NoopProvider. Then look at the initKeystore and ensureProviderClosesBeforeKeystore lifecycle hooks, which skip NoopProvider. Run the reproduction test, which opens and closes the same repo twice in one process, and make it pass. Done means that test and go test ./core/node/ both pass, with the keystore closed on the nil-DHT path.
Written by the indexing model from the issue text.
Description
AI disclosure: this bug was found while analyzing a package that is not yet published on pub.dev, and the analysis, the reproduction and the proposed fix below were made entirely with AI (Claude). The author wants everyone who reads this issue (and any PR that follows) to know that, and acknowledges that, despite an extensive battery of tests, AI can still make mistakes.
Checklist
- This is a bug report, not a question.
- I have searched the issue tracker for my bug.
- I am running the latest kubo version (v0.43.1; the same code is on
master, 833e04a240d8).
Installation method
Built from source, kubo used as a library (core.NewNode), Go 1.26.5, linux/amd64 and windows/amd64.
Config
config.Init + the test profile, node built with Routing: libp2p.NilRouterOption (the same as Routing.Type none). Everything else default.
Description
With routing none, closing a node leaves the provider keystore datastore (<repo>/provider-keystore/<n>) open. Opening the same repo again in the same process then fails on its lock:
- Windows:
constructing the node (see log for full detail): failed to create datastore for namespace 0: The process cannot access the file because it is being used by another process. - Linux:
... resource temporarily unavailable
The ipfs daemon CLI does not notice because the process exits, but anything that embeds kubo and restarts a node in-process does (tests, apps).
Reproduction:
package repro
import (
"context"
"io"
"os"
"testing"
"github.com/ipfs/kubo/config"
"github.com/ipfs/kubo/core"
"github.com/ipfs/kubo/core/node/libp2p"
"github.com/ipfs/kubo/plugin/loader"
"github.com/ipfs/kubo/repo/fsrepo"
)
func TestNilRoutingReopen(t *testing.T) {
pl, _ := loader.NewPluginLoader("")
pl.Initialize()
pl.Inject()
ctx := context.Background()
dir, _ := os.MkdirTemp("", "repro")
cfg, _ := config.Init(io.Discard, 2048)
config.Profiles["test"].Transform(cfg)
if err := fsrepo.Init(dir, cfg); err != nil {
t.Fatal(err)
}
start := func() error {
r, err := fsrepo.Open(dir)
if err != nil {
return err
}
n, err := core.NewNode(ctx, &core.BuildCfg{Online: true, Repo: r, Routing: libp2p.NilRouterOption})
if err != nil {
r.Close()
return err
}
return n.Close()
}
if err := start(); err != nil {
t.Fatal(err)
}
if err := start(); err != nil {
t.Fatal(err) // fails here
}
}
Cause: in SweepingProviderOpt (core/node/provider.go) the fx.Provide creates the ResettableKeystore, which opens the on-disk datastore, before it knows whether there is a DHT to provide with. With no DHT (impl == nil) it returns &NoopProvider{}, nil, nil, dropping the keystore without closing it, and both lifecycle hooks that would close it (initKeystore and ensureProviderClosesBeforeKeystore) return early for *NoopProvider.
Proposed fix, which we have been running as a local patch (the reproduction passes, and go test ./core/node/ still passes):
if impl == nil {
+ // No DHT to provide with: the keystore opened above goes unused,
+ // and the shutdown hooks skip the NoopProvider, so close it here.
+ if err := ks.Close(); err != nil {
+ return nil, nil, err
+ }
return &NoopProvider{}, nil, nil
}
If this looks right, we can open a PR with a regression test.
- Dominant language
- Go
- Stars
- 17.2k
- Forks
- 3.2k
- PR merge metrics
- No merged PRs in 30d
Getting set up
- Ships a Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from ipfs/kubo
-
kind/bug need/triage
Difficulty 1/5 Under an hour Newbie friendliness 65/100
-
Difficulty 5/5 Over a week Newbie friendliness 14/100
-
Difficulty 4/5 3-5 days Newbie friendliness 48/100
-
System.ConnsInbound fills with leaked reservations, refusing peers while ConnMgr is below HighWaterOpen
Difficulty 4/5 3-5 days Newbie friendliness 42/100
-
kind/feature need/triage
Difficulty 5/5 Over a week Newbie friendliness 35/100
Similar issues
-
Pin and verify Security Insights schema in lintinsights targetPossibly taken @imshubham22apr-gif claimed this 5 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
gemaraproj/gemara#618 ·
Maintainers usually reply within 2 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
a2aproject/a2a-go#597 ·
Maintainers usually reply within 1 day
-
scopes: GetAllowedTopics, GetProtectedTopics, and GetScopedTopics include empty topic names and do not trim whitespace charactersPossibly taken @patelshivani2283-lab claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
area/networking kind/bug
Difficulty 2/5 1-3 hours Newbie friendliness 69/100
siderolabs/talos#14972 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 72/100
Maintainers usually reply within 1 day