-
Notifications
You must be signed in to change notification settings - Fork 42
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 terminate database connection in omdb #7290
Properly terminate database connection in omdb #7290
Conversation
Otherwise attempting to do an action that requires a DestructionToken will cause a panic, as it returns from `run_cmd` before calling terminate on the datastore.
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.
Looks good to me, though I commented on some smallish style suggestions.
dev-tools/omdb/src/bin/omdb/db.rs
Outdated
pub(crate) async fn run_cmd( | ||
&self, | ||
omdb: &Omdb, | ||
log: &slog::Logger, | ||
) -> Result<(), anyhow::Error> { | ||
let datastore = self.db_url_opts.connect(omdb, log).await?; | ||
let res = self.run_cmd_inner(&datastore, omdb, log).await; |
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.
Take it or leave it: we might want to define run_cmd_inner
as a function within the scope of run_cmd
, as that will prevent it from being called outside run_cmd
, even by other code within this module (which making it module-private doesn't achieve). This might be worth doing if we want to be extra certain that nobody accidentally does the wrong thing.
See this playground demonstrating what I mean.
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.
Alternatively, run_cmd_inner
could just be an async
block within run_cmd
that we immediately .await
, as early returns in the async
block won't return from the outer function, just the async block (example). That way, we don't need to have a whole other function for it. Up to you if you think that's nicer...
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.
Done!
Otherwise attempting to do an action that requires a DestructionToken will cause a panic, as it returns from
run_cmd
before calling terminate on the datastore.