From fd93334a21907f959018e1b1f5df747a98d186c8 Mon Sep 17 00:00:00 2001 From: salmonik Date: Wed, 4 Nov 2026 01:11:50 +0100 Subject: processes: add timeouts and keep decoding off the runtime --- src/commands/qr.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'src/commands/qr.rs') diff --git a/src/commands/qr.rs b/src/commands/qr.rs index 26232ee..c0b8af0 100644 --- a/src/commands/qr.rs +++ b/src/commands/qr.rs @@ -61,10 +61,14 @@ pub async fn dekodowanie( .await? .bytes() .await?; - let img = image::load_from_memory(&img_data)?; - let gray = img.to_luma8(); - - let decoded = decode_qr_simple(&gray); + // Decoding is CPU-heavy: keep it off the async runtime. + let img_data = img_data.to_vec(); + let decoded = tokio::task::spawn_blocking(move || { + let img = image::load_from_memory(&img_data).ok()?; + let gray = img.to_luma8(); + decode_qr_simple(&gray) + }) + .await?; match decoded { Some(text) => { ctx.say(lang::fmt_qr_decoded(&text)).await?; -- cgit v1.2.3