DEV Community

Discussion on: How to use gRPC with Rust Tonic and Postgres database with examples

hhanh00 profile image

Unfortunately, this code doesn't work with more recent versions of the tonic and postgres libraries.

You will hit the error:

thread 'tokio-runtime-worker' panicked at 'Cannot start a runtime from within a runtime. This happens because a function (like `block_on`) attempted to block the current thread while the thread is being used to drive asynchronous tasks.'
Enter fullscreen mode Exit fullscreen mode

Because postgres driver executes runtime.block_on inside the block_on coming from #[tokio:main]

steadylearner profile image
Steadylearner Author • Edited on

Thanks for letting the comment to help others. I will upgrade it later if I have to use Rust with gRPC again. Until then, it will be better to read this post only to learn the workflow to use gRPC with Rust and Tonic.