From 29fe8dce1ef6bac807717a9416282f6170010436 Mon Sep 17 00:00:00 2001 From: Vika Date: Fri, 6 Aug 2021 07:52:50 +0300 Subject: Shortened a connection timeout and installed a lifetime limit for connection --- src/database/redis/mod.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/database/redis/mod.rs b/src/database/redis/mod.rs index 00932de..3a0d5fc 100644 --- a/src/database/redis/mod.rs +++ b/src/database/redis/mod.rs @@ -10,6 +10,7 @@ use mobc_redis::redis; use mobc_redis::redis::AsyncCommands; use mobc_redis::RedisConnectionManager; use serde_json::json; +use std::time::Duration; use crate::database::{ErrorKind, MicropubChannel, Result, Storage, StorageError}; use crate::indieauth::User; @@ -292,7 +293,7 @@ impl Storage for RedisStorage { // Happens because of a broken link (result of an improper deletion?) None => Ok(None), }, - Err(err) => Err(StorageError::from(err)) + Err(err) => Err(StorageError::with_source(ErrorKind::Backend, "Error executing a Redis command", Box::new(err))) } } Err(err) => Err(StorageError::with_source(ErrorKind::Backend, "Error getting a connection from the pool", Box::new(err))) @@ -360,6 +361,8 @@ impl RedisStorage { redis: Pool::builder() .max_open(20) .max_idle(5) + .get_timeout(Some(Duration::from_secs(3))) + .max_lifetime(Some(Duration::from_secs(120))) .build(RedisConnectionManager::new(client)), }), Err(e) => Err(e.into()), -- cgit 1.4.1