djc / bb8

Full-featured async (tokio-based) postgres connection pool (like r2d2)
MIT License
753 stars 110 forks source link

`schedule_reaping` doesn't work well with actix. #44

Closed stoksc closed 4 years ago

stoksc commented 4 years ago

Have a bit of an issue. I decided to dip my toes in by trying to make actix-web run async/await with a pool. Went with bb8 because you're on new futures already 👍 🎊

After a little work, I ended up with this error over and over again:

thread '' panicked at 'called Result::unwrap() on an Err value: SpawnError { is_shutdown: true }'

getting thrown from inside bb8's Pool. After looking into it some more, it's because the reaper is spawned off immediately on building the pool, but the tokio runtime isn't ready until you call System::run on the actix system. However, I need to build the pool to give to the actix_web::HttpServer before I start the system.

Not entirely a bb8 issue, I'm sure it works fine with hyper but I was wondering if you had any ideas.

Validated by forking and just commenting out where the reaper is scheduled. Works fine and I get a db connection.

khuey commented 4 years ago

Can you post a little code sample somewhere of what's failing for you?

stoksc commented 4 years ago

Yeah sure, here it is https://gitlab.com/stoked_/actix-bb8-try/tree/master

stoksc commented 4 years ago

Didn't really have a grasp on actix when I opened this, actix has it's own runtime in the actix-rt packages.. trying to spawn just with tokio::spawn results in an error (no executor) but patching bb8 to use actix_rt::spawn works just fine. Rehosted the working example on github. Looks like actix-rt will have an #[actix_rt::main] for async mains, to remove some of the complexity from this.

https://github.com/stoksc/actix-bb8-service

Patched bb8:

https://github.com/stoksc/bb8

khuey commented 4 years ago

This seems like something that actix and tokio need to sort out because forking every async library is nuts.

stoksc commented 4 years ago

Totally agree. State of async/await in rust right now is less than desirable..

For now I'll just stick to hyper since they seem to get along.