|
@@ -8,6 +8,8 @@ use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
|
|
|
use std::sync::{Arc, Condvar, Mutex};
|
|
|
use std::time::Duration;
|
|
|
|
|
|
+use tokio::time::Instant;
|
|
|
+
|
|
|
use crate::database::DatabaseConnector;
|
|
|
|
|
|
/// Pool error
|
|
@@ -163,10 +165,12 @@ where
|
|
|
timeout: Duration,
|
|
|
) -> Result<PooledResource<RM>, Error<RM::Error>> {
|
|
|
let mut resources = self.queue.lock().map_err(|_| Error::Poison)?;
|
|
|
+ let time = Instant::now();
|
|
|
|
|
|
loop {
|
|
|
if let Some((stale, resource)) = resources.pop() {
|
|
|
if !stale.load(Ordering::SeqCst) {
|
|
|
+ tracing::warn!("Got resource");
|
|
|
drop(resources);
|
|
|
self.in_use.fetch_add(1, Ordering::AcqRel);
|
|
|
|
|
@@ -178,6 +182,7 @@ where
|
|
|
}
|
|
|
|
|
|
if self.in_use.load(Ordering::Relaxed) < self.max_size {
|
|
|
+ tracing::warn!("Got resource");
|
|
|
drop(resources);
|
|
|
self.in_use.fetch_add(1, Ordering::AcqRel);
|
|
|
let stale: Arc<AtomicBool> = Arc::new(false.into());
|
|
@@ -197,6 +202,11 @@ where
|
|
|
.map_err(|_| Error::Poison)
|
|
|
.and_then(|(lock, timeout_result)| {
|
|
|
if timeout_result.timed_out() {
|
|
|
+ tracing::warn!(
|
|
|
+ "Timeout waiting for the resource (pool size: {}). Waited {} ms",
|
|
|
+ self.max_size,
|
|
|
+ time.elapsed().as_millis()
|
|
|
+ );
|
|
|
Err(Error::Timeout)
|
|
|
} else {
|
|
|
Ok(lock)
|