{"record":{"id":"0e850b296db3119d","repo":"OrchardCMS/OrchardCore","slug":"the-clamav-antivirus-scanner-could-not-be-reached-while","errorCode":null,"errorMessage":"The ClamAV antivirus scanner could not be reached while scanning '{context.FileName}'.","messagePattern":"The ClamAV antivirus scanner could not be reached while scanning '(.+?)'\\.","errorType":"exception","errorClass":"AntivirusScanningException","httpStatus":null,"severity":"error","filePath":"src/OrchardCore.Modules/OrchardCore.Antivirus/ClamAV/ClamAvFileEventHandler.cs","lineNumber":77,"sourceCode":"            if (scanStream != stream)\n            {\n                await scanStream.DisposeAsync();\n            }\n\n            _logger.LogError(exception, \"ClamAV timed out while scanning '{FileName}'.\", context.FileName);\n\n            throw new AntivirusScanningException($\"The ClamAV antivirus scanner timed out while scanning '{context.FileName}'.\", exception);\n        }\n        catch (SocketException exception)\n        {\n            if (scanStream != stream)\n            {\n                await scanStream.DisposeAsync();\n            }\n\n            _logger.LogError(exception, \"ClamAV could not be reached while scanning '{FileName}'.\", context.FileName);\n\n            throw new AntivirusScanningException($\"The ClamAV antivirus scanner could not be reached while scanning '{context.FileName}'.\", exception);\n        }\n        catch (IOException exception)\n        {\n            if (scanStream != stream)\n            {\n                await scanStream.DisposeAsync();\n            }\n\n            _logger.LogError(exception, \"ClamAV failed while scanning '{FileName}'.\", context.FileName);\n\n            throw new AntivirusScanningException($\"The ClamAV antivirus scanner failed while scanning '{context.FileName}'.\", exception);\n        }\n        catch\n        {\n            if (scanStream != stream)\n            {\n                await scanStream.DisposeAsync();\n            }","sourceCodeStart":59,"sourceCodeEnd":95,"githubUrl":"https://github.com/OrchardCMS/OrchardCore/blob/4306c0717fe573f6fca1b4955909ddab6a192807/src/OrchardCore.Modules/OrchardCore.Antivirus/ClamAV/ClamAvFileEventHandler.cs#L59-L95","documentation":"The ClamAV file event handler catches SocketException from the clamd TCP connection and rethrows it as an AntivirusScanningException with this message. It means the upload pipeline could not establish or maintain a socket connection to the ClamAV daemon while scanning a file.","triggerScenarios":"CreatingAsync calls _connectionFactory.Create(_options).ScanAsync and the TCP connect or stream I/O to options.Host:options.Port raises SocketException (host unresolvable/unreachable, connection refused, reset).","commonSituations":"clamd container not running or crashed, wrong host/port configuration, DNS resolution failure in containerized environments, network partition or firewall blocking port 3310.","solutions":["Verify ClamAV daemon is running and listening (e.g. `docker ps`, `systemctl status clamav-daemon`).","Confirm options.Host and options.Port point at the correct clamd address (default 3310).","Test connectivity from the app host: `telnet clamd-host 3310` or `nc -vz`.","Check container networking/DNS (service name on the same Docker network) and firewall rules."],"exampleFix":"// before\noptions.Host = \"localhost\"; // in a container, clamd is not on localhost\n// after\noptions.Host = \"clamd\"; // docker-compose service name, port 3310","handlingStrategy":"retry","validationCode":"// preflight connectivity check\nusing var tcp = new System.Net.Sockets.TcpClient();\nawait tcp.ConnectAsync(options.Host, options.Port); // throws if clamd unreachable","typeGuard":null,"tryCatchPattern":"try\n{\n    await UploadFileAsync(stream);\n}\ncatch (AntivirusScanningException ex) when (ex.InnerException is SocketException)\n{\n    logger.LogError(ex, \"clamd unreachable at {Host}:{Port}\", options.Host, options.Port);\n    // surface a friendly 'service temporarily unavailable' message\n}","preventionTips":["Health-check the clamd endpoint on app startup and periodically.","Use stable DNS/service names in container orchestration.","Pin clamd service restart policies so it auto-recovers.","Document the required host/port in deployment configuration."],"tags":["clamav","socket","network","connection"],"backgroundTag":"connection-refused","analyzedSha":"4306c0717fe573f6fca1b4955909ddab6a192807","analyzedAt":"2026-09-13T17:41:05.024Z","contentChangedAt":"2026-09-13T17:41:05.024Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}