fix(thumbnail): add timeout protection for large image processing
Resolves conflict between main and PR #229 by applying timeout support on top of main's drop(data) memory optimization. Changes: - Add thumbnail_generation_ms to TimeoutConfig (default 30s) - Add generation_timeout field to ThumbnailService - Wrap spawn_blocking in tokio::time::timeout to prevent hanging - Update DI to pass timeout from config - Update tests to provide timeout parameter https://claude.ai/code/session_015FD62aAoMYx1XBZbzPvUu8
This commit is contained in:
+12
-4
@@ -34,15 +34,18 @@ pub struct TimeoutConfig {
|
||||
pub lock_acquisition_ms: u64,
|
||||
/// Timeout for network operations (ms)
|
||||
pub network_operation_ms: u64,
|
||||
/// Timeout for thumbnail generation (ms)
|
||||
pub thumbnail_generation_ms: u64,
|
||||
}
|
||||
|
||||
impl Default for TimeoutConfig {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
file_operation_ms: 10000, // 10 seconds
|
||||
dir_operation_ms: 30000, // 30 seconds
|
||||
lock_acquisition_ms: 5000, // 5 seconds
|
||||
network_operation_ms: 15000, // 15 seconds
|
||||
file_operation_ms: 10000, // 10 seconds
|
||||
dir_operation_ms: 30000, // 30 seconds
|
||||
lock_acquisition_ms: 5000, // 5 seconds
|
||||
network_operation_ms: 15000, // 15 seconds
|
||||
thumbnail_generation_ms: 30000, // 30 seconds
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -82,6 +85,11 @@ impl TimeoutConfig {
|
||||
pub fn network_timeout(&self) -> Duration {
|
||||
Duration::from_millis(self.network_operation_ms)
|
||||
}
|
||||
|
||||
/// Gets a Duration for thumbnail generation operations
|
||||
pub fn thumbnail_timeout(&self) -> Duration {
|
||||
Duration::from_millis(self.thumbnail_generation_ms)
|
||||
}
|
||||
}
|
||||
|
||||
/// Configuration for large resource handling
|
||||
|
||||
+2
-1
@@ -119,12 +119,13 @@ impl AppServiceFactory {
|
||||
}));
|
||||
tracing::info!("FileContentCache initialized: max 10MB/file, 512MB total, 10k entries");
|
||||
|
||||
// Thumbnail service for thumbnail generation
|
||||
// Thumbnail service for thumbnail generation with timeout protection
|
||||
let thumbnail_service = Arc::new(
|
||||
crate::infrastructure::services::thumbnail_service::ThumbnailService::new(
|
||||
&self.storage_path,
|
||||
5000, // max 5000 thumbnails in cache
|
||||
100 * 1024 * 1024, // max 100MB cache
|
||||
Some(self.config.timeouts.thumbnail_timeout()),
|
||||
),
|
||||
);
|
||||
// Initialize thumbnail directories
|
||||
|
||||
Reference in New Issue
Block a user