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 terminate database connection in omdb #7290

Merged
merged 3 commits into from
Jan 21, 2025

Conversation

jmpesp
Copy link
Contributor

@jmpesp jmpesp commented Dec 20, 2024

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.

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.
@jmpesp jmpesp requested a review from davepacheco December 20, 2024 17:30
Copy link
Member

@hawkw hawkw left a 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.

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;
Copy link
Member

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.

Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

@jmpesp jmpesp enabled auto-merge (squash) January 21, 2025 17:03
@jmpesp jmpesp merged commit b01186d into oxidecomputer:main Jan 21, 2025
16 checks passed
@jmpesp jmpesp deleted the terminate_datastore_in_omdb branch January 21, 2025 19:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants