Skip to content

Conversation

@coolreader18
Copy link
Collaborator

Description of Changes

Follow-up to #2737. I added this utility function in #2730, and it makes the logic of these kinds of spawn_blocking uses clearer.

Expected complexity level and risk

1

Testing

n/a - the code is equivalent.

@coolreader18 coolreader18 requested a review from jsdt May 15, 2025 17:23
@coolreader18
Copy link
Collaborator Author

I also edited the comment - it's obviously not that we care about having to use std::panic::AssertUnwindSafe, it's that the operation is blocking.

@coolreader18
Copy link
Collaborator Author

There's a similar use in HostController::using_database, ftr:

    pub async fn using_database<F, T>(&self, database: Database, replica_id: u64, f: F) -> anyhow::Result<T>
    where
        F: FnOnce(&RelationalDB) -> T + Send + 'static,
        T: Send + 'static,
    {
        trace!("using database {}/{}", database.database_identity, replica_id);
        let module = self.get_or_launch_module_host(database, replica_id).await?;
        let on_panic = self.unregister_fn(replica_id);
        scopeguard::defer_on_unwind!({
            warn!("database operation panicked");
            on_panic();
        });
        let result = asyncify(move || f(&module.replica_ctx().relational_db)).await;
        Ok(result)
    }

@coolreader18 coolreader18 enabled auto-merge May 15, 2025 17:38
@coolreader18 coolreader18 added this pull request to the merge queue May 15, 2025
Merged via the queue into master with commit 0829f7d May 15, 2025
20 checks passed
drogus added a commit that referenced this pull request Jun 17, 2025
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.

3 participants