Why is diesel not compatible with async?

Say we have an async function, that has more than one async calls:

async fn foo() {

Each of the await is a point where the async task could pause. The design of async in rust allows a task that is awaiting to be moved from one thread to another.

Now diesel uses libpq internally, which comes with this caveat:

One thread restriction is that no two threads attempt to manipulate the same PGconn object at the same time. In particular, you cannot issue concurrent commands from different threads through the same connection object. (If you need to run concurrent commands, use multiple connections.)

So we can not pass connection to a async function that can have more than one await calls.

We can circumvent this maybe by passing around diesel connection pool instead of a connection, and letting each await fetch a connection and then execute the connection.

But this does not work in presence of transactions. For transaction, it is required that same connection be used for each statement in the transaction.

Table Of Content

Immobile v2


Link Log

August 2020

July 2020

June 2020

May 2020

April 2020

March 2020

February 2020

January 2020


Books Have Read / Recommend

Product Management Books

Badass: Making Users Awesome


Five Cs of An Organisation

Success and failure of encryption

Open Source

Observer: Observability for Rust

Realm: Web Development Framework Using Rust and Elm

MartD: Server To Browser Messages

On Writing And Formats Of Written Communications

Rust Stuff

Rust feature flags

Why is diesel not compatible with async?

Making Postgres Only Diesel Code To Also Support Sqlite

Rust Git2’s Concepts

Git Hash And Build Date In Rust Build

Systray Only Native App In Rust

Software and Tools I Use Often


DNS Over HTTPS Controversy

The Patel Motel Cartel

Standalone Complex


January 2020

Word Of The Day





Nix On OSX Catalina

Postgres: WAL / Logical Decoding

Postgres: Listen-Notify



Go All The Way

SSH Commands



Nu Shell

SHA256 vs SHA224

Pronouns Bad


Web Components

Early Return