`Pool::disconnect` waits forever, how to disconnect correctly?
heavycharged opened this issue · 3 comments
Hi, i am beginner in Rust, trying to write some small app. I trying to create graceful shutdown for my app, and i ran into problem when Pool::disconnect
waits forever. Docs states that it will waits until all taken conns are dropped, but i cannot understand why the Conn
is not dropped. I've created a MRE. Can someone check and explain me where i went wrong? Thanks.
@heavycharged Are you using BinLogStream, because this happens when you do acquire a connection using BinLogStream for example, I made a PR to fix that #200
Hey, @oussama. Thanks for reply, but i am not using BinlogStream
.
Here is minimal reproducible example, it simply calls SELECT 42
from database.
The problem occurs only when i spawn actix_web::HttpServer
. If i remove code with HttpServer
, and simply make some requests, everything works fine and Pool::disconnect
finishes in few moments.
In my example #[actix_web::rt]
used, but switching to tokio
runtime not helps to solve the problem (i guess actix
uses tokio
runtime in last versions).
I thought that actix_web
shutdowns the runtime when handling the Ctrl+C
, so i tried to disable signal handler with disable_signals()
and handle it manually. This not helps, it still freezes.
@heavycharged, thanks for reporting this.
As far as I was able to understand Actix runs HttpServer futures on tokio's LocalSet (or on a set of LocalSets), so as soon as HttpServer future resolves the LocalSet is dropped as well as all tasks that started inside of it (including mysql_async's Recycler). Actually, you can fix this by running Recycler before spawning HttpServer (Recycler will be spawned at the first call to Pool::get_conn).
Previous implementation assumed that Recycler will be dropped only in the case, when the whole runtime is shutting down, i.e. in the case when DisconnectPool
future is also dropped, but this is not the case here.
#205 fixes this issue, but I don't think that it covers all corner cases, so feel free to reopen.