Skip to content
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

Merged
merged 2 commits into from
Jan 23, 2020
Merged

Conversation

mrBliss
Copy link
Contributor

@mrBliss mrBliss commented Jan 22, 2020

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 ClosedDBErrors.

@mrBliss mrBliss added consensus issues related to ouroboros-consensus chain db immutable db labels Jan 22, 2020
@mrBliss mrBliss requested review from edsko and nfrisby January 22, 2020 16:10
@mrBliss mrBliss force-pushed the mrBliss/fix-1470 branch 2 times, most recently from 8b7c69d to 0f303ad Compare January 23, 2020 09:11
:: 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
Copy link
Contributor Author

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 Internalr 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)
Copy link
Contributor Author

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.

Copy link
Contributor

@edsko edsko left a 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.
@mrBliss
Copy link
Contributor Author

mrBliss commented Jan 23, 2020

bors r+

iohk-bors bot added a commit that referenced this pull request Jan 23, 2020
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>
@edsko
Copy link
Contributor

edsko commented Jan 23, 2020

bors r-

@iohk-bors
Copy link
Contributor

iohk-bors bot commented Jan 23, 2020

Canceled

@edsko
Copy link
Contributor

edsko commented Jan 23, 2020

🙄

@mrBliss
Copy link
Contributor Author

mrBliss commented Jan 23, 2020

bors r+

iohk-bors bot added a commit that referenced this pull request Jan 23, 2020
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>
@iohk-bors
Copy link
Contributor

iohk-bors bot commented Jan 23, 2020

@iohk-bors iohk-bors bot merged commit bf4d1c4 into master Jan 23, 2020
@iohk-bors iohk-bors bot deleted the mrBliss/fix-1470 branch January 23, 2020 13:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chain db consensus issues related to ouroboros-consensus immutable db
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ImmDB.closeDB should not call releaseAll on the passed-in registry
2 participants