Repository navigation
fix(provider): close keystore when no provider takes ownership - #11493
Open
amalsaidov wants to merge 1 commit into
Open
amalsaidov wants to merge 1 commit into
amalsaidov wants to merge 1 commit into
Conversation
With Routing.Type=none the provider is a NoopProvider and the keystore is never handed off, but NewResettableKeystore already opened its datastore under <repo>/provider-keystore/. Nothing closed it, so the datastore kept its lock and reopening the same repo in the same process failed (Linux: "resource temporarily unavailable"; Windows: "being used by another process"). Software that embeds Kubo and restarts a node in-process hit this; the daemon CLI did not, because process exit released the lock. Close the keystore on every path that does not pass it to a provider, covering the NoopProvider case and provider construction errors.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed
With
Routing.Type=none(or a node built with the nil router) Kubo builds aNoopProvider, so no provider ever takes ownership of the DHT provider keystore.NewResettableKeystorestill runs before that decision and, in factory mode, eagerly opens the active namespace datastore under<repo>/provider-keystore/. The constructor then returnsNoopProviderwith anilkeystore and the opened datastore is dropped on the floor:initKeystoreandensureProviderClosesBeforeKeystoreboth skipNoopProvider, so nothing closes it.The leaked datastore keeps its lock for the life of the process. Reopening the same repo in the same process then fails:
failed to create datastore for namespace 0: ... resource temporarily unavailable... The process cannot access the file because it is being used by another process.The
ipfs daemonCLI does not notice because the process exits and the OS releases the lock, but anything that embeds Kubo and restarts a node in-process (tests, apps) does.Fix
Close the keystore on every path out of the provider constructor that does not hand it to a provider. A single deferred close guarded by a
keystoreHandedOffflag covers theNoopProvidercase and the provider-construction error paths; the flag is set right before the two returns that pass the keystore to abuffered.New(...)provider.ResettableKeystore.Closeis idempotent and only persists/syncs size and closes the datastores it owns (it does not delete data or touch the caller-owned repo datastore), so closing an unused keystore is safe.Test
core.TestNilRoutingKeystoreReopeninits an on-disk (pebbleds) repo, builds and closes a node withRouting: none, then builds it again in the same process. An in-memory datastore takes no lock, so the test uses an on-disk one and also assertsprovider-keystore/was created. The test fails before the fix (failed to create datastore for namespace 0: ... lock held by current process) and passes after.go vet ./core/... ./core/node/andgo test ./core/node/are clean.golangci-lintreports no issues in the changed files (the only failure is a pre-existing stylecheck warning infuse/node/mount_darwin.go, unrelated to this change).AI-assisted; directed, reviewed and tested by the author (amalsaidov).
References