Open xuxiaocheng0201 opened 5 months ago
I tried my best to resolve the question:
while let Err(e) = tokio::fs::remove_file("1.db").await {
tokio::task::yield_now().await;
}
But it's not perfect.
I've never thought about that but it makes perfect sense to have that feature. You basically want to wait for all objects returned from the pool to be dropped.
I'm currently thinking of adding a return value to Pool::close
which gives you the ability to .await
it.
I can think of two ways to implement this:
0
there should be no connections whatsoever.tokio::sync::watch
to all objects so they can report their state (Ready, Dropping, Dropped). For that to work the pool would need to keep a reference to all the objects it created. Similar to the way deadpool-postgres
keeps track of the objects so that the StatementCaches
can be empied via the manager.Even though it's a lot more involved I'm almost leaning towards the second implementation. It always bugged me a bit that deadpool-postgres
keeps track of the StatementCaches
and not the entire object. e.g. It would be nice if it was also possible to access the Metrics
of objects which are currently not living inside the pool.
Related to:
When I removing the sqlite db file, I occurred an os error 32.
Error: 另一个程序正在使用此文件,进程无法访问。 (os error 32)
It meansAnother program is using this file and the process cannot access it
. This is a common error in windows.I have found the code that caused this problem. In SyncWrapper, the connection resource will be dropped in a background task. However, I have no way of knowing whether this task has been completed or not. So if I remove the db file immediately after dropping the pool, this error will occur.
So is there any way to ensure the connections is completely dropped? or block on when the
SyncWrapper
is dropping?Reproduce:
Cargo.toml
:main.rs
: