Skip to content

How to properly exec a long-running database operation during the launching phase? #2187

Answered by the10thWiz
tumluliu asked this question in Questions
Discussion options

You must be logged in to vote

It's a bit strange to me that although the postgres::Client is actually a synchronous PostgreSQL client as its document says, why the creation of it will cause a nested tokio runtime issue?

Looking into the postgres crate, it looks like it starts it's own async runtime and runs an async client on the runtime it creates. It's technically a sync client (since it doesn't need an async runtime), but it can't actually be started within a tokio runtime due to some things tokio does. The simple solution here would actually be to use something like tokio-postgres, an async client (since Rocket already creates a tokio runtime, you might as well use it). The postgres crate actually uses tokio-pos…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@SergioBenitez
Comment options

@tumluliu
Comment options

Answer selected by tumluliu
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants