fix(malware): an unreachable or silent clamd is logged as an error
CI / Check (push) Skipped
CI / Detect Changes (pull_request) Skipped
CI / Deploy Agent (pull_request) Skipped
CI / Deploy Dashboard (pull_request) Skipped
CI / Deploy Docs (pull_request) Skipped
CI / Deploy MCP (pull_request) Skipped
CI / Check (pull_request) Successful in 8m31s

On stage clamd was down for a day and the only trace was WARN lines, so the
"ERROR/FATAL logs" alert never fired. Unreachable and timed-out clamd now log
at ERROR; a refused file or an unreadable tree stays a warning. The scan run
still records the malware stage as skipped, as before.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p
This commit is contained in:
Sharang ParnerkarandClaude Opus 5.5 committed 2026-10-09 14:48:39 +02:00
1 parent e396141490
commit 89ad1b0d4b
2 files changed
+27 -1

No files matched your search

+22
View File
@@ -69,6 +69,18 @@ pub enum ClamavError {
Io(#[from] std::io::Error),
}
impl ClamavError {
/// True when the clamd service itself is down (unreachable or silent),
/// as opposed to a problem with one file or the tree. Logged as an error
/// so the "ERROR/FATAL logs" alert fires: nothing else restarts clamd.
pub fn service_down(&self) -> bool {
match self {
Self::Unreachable(..) | Self::Timeout => true,
Self::Refused(_) | Self::Io(_) => false,
}
}
}
/// A clamd service.
#[derive(Debug, Clone)]
pub struct Clamd {
@@ -397,6 +409,16 @@ fn finding(root: &Path, repo_id: &str, file: &Path, hash: &str, signature: &str)
mod tests {
use super::*;
#[test]
fn only_an_unreachable_or_silent_clamd_is_down() {
let refused = std::io::Error::from(std::io::ErrorKind::ConnectionRefused);
assert!(ClamavError::Unreachable("clamav:3310".into(), refused).service_down());
assert!(ClamavError::Timeout.service_down());
assert!(!ClamavError::Refused("INSTREAM size limit exceeded".into()).service_down());
let unreadable = std::io::Error::from(std::io::ErrorKind::PermissionDenied);
assert!(!ClamavError::Io(unreadable).service_down());
}
#[test]
fn clamd_answers_are_read() {
assert_eq!(
@@ -2117,7 +2117,11 @@ impl PipelineOrchestrator {
findings.extend(scan.findings);
}
Err(e) => {
tracing::warn!("[{repo_id}] ClamAV did not complete: {e}");
if e.service_down() {
tracing::error!("[{repo_id}] ClamAV did not complete: {e}");
} else {
tracing::warn!("[{repo_id}] ClamAV did not complete: {e}");
}
self.skip_stage(
scan_run_id,
SkippedStage::new(