-
Notifications
You must be signed in to change notification settings - Fork 86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Properly shut down a node, its DBs, and its threads #1488
Conversation
8b7c69d
to
0f303ad
Compare
:: IOLike m | ||
=> CacheEnv m hash h | ||
-> EpochNo -- ^ The new current epoch | ||
-> m () | ||
reset cacheEnv@CacheEnv { hasFS, err, hashInfo, registry, cacheVar } epoch = do | ||
restart cacheEnv epoch = do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a comment that this is used only in the tests (it doesn't leak past the ImmutableDB, because the only code path that triggers it is part of the Internal
r ecord) and that we don't have to worry about race conditions involving bgThreadVar
.
-- and the registry, so we must use 'unsafeReleaseAll' instead of | ||
-- 'releaseAll'. | ||
(DbClosed, unsafeReleaseAll _dbRegistry) | ||
(DbClosed, cleanUp hasFS st) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let open
return an OpenState
and close
take one, so that we can make sure that we only clean up an OpenState
. I.e., we cannot have accidentally closed the state already before trying to clean it up.
Same for withOpenState
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, but let's change cleanup
to take an option state.
Fixes #1470. * Don't use `releaseAll` or `unsafeReleaseAll` in the ImmutableDB, as that will terminate all background threads, not just the resources using the ImmutableDB. Instead, use `Index.close` to shut down the background thread. * Start and close the ChainDB using the `ResourceRegistry` instead of using `withChainDB`, this makes sure that resources are released in the right order. Previously, the ChainDB was being closed before the background threads using it were terminated, resulting in `ClosedDBError`s.
Previously, `open` and `close` returned/took an `InternalState` which could either be a `ClosedState` or an `OpenState`. Now, we return/take an `InternalState` so that in `close`, we can't accidentally pass an already closed state to `cleanUp` instead of the previous open state.
5d45380
to
bf4d1c4
Compare
bors r+ |
1488: Properly shut down a node, its DBs, and its threads r=mrBliss a=mrBliss Fixes #1470. * Don't use `releaseAll` or `unsafeReleaseAll` in the ImmutableDB, as that will terminate all background threads, not just the resources using the ImmutableDB. Instead, use `Index.close` to shut down the background thread. * Start and close the ChainDB using the `ResourceRegistry` instead of using `withChainDB`, this makes sure that resources are released in the right order. Previously, the ChainDB was being closed before the background threads using it were terminated, resulting in `ClosedDBError`s. Co-authored-by: Thomas Winant <thomas@well-typed.com>
bors r- |
Canceled |
🙄 |
bors r+ |
1488: Properly shut down a node, its DBs, and its threads r=mrBliss a=mrBliss Fixes #1470. * Don't use `releaseAll` or `unsafeReleaseAll` in the ImmutableDB, as that will terminate all background threads, not just the resources using the ImmutableDB. Instead, use `Index.close` to shut down the background thread. * Start and close the ChainDB using the `ResourceRegistry` instead of using `withChainDB`, this makes sure that resources are released in the right order. Previously, the ChainDB was being closed before the background threads using it were terminated, resulting in `ClosedDBError`s. 1496: Address review feedback on #1425. r=edsko a=edsko Co-authored-by: Thomas Winant <thomas@well-typed.com> Co-authored-by: Edsko de Vries <edsko@well-typed.com>
Fixes #1470.
Don't use
releaseAll
orunsafeReleaseAll
in the ImmutableDB, as that will terminate all background threads, not just the resources using the ImmutableDB. Instead, useIndex.close
to shut down the background thread.Start and close the ChainDB using the
ResourceRegistry
instead of usingwithChainDB
, this makes sure that resources are released in the right order. Previously, the ChainDB was being closed before the background threads using it were terminated, resulting inClosedDBError
s.