{"record":{"id":"510b65acc89ae4cd","repo":"OrchardCMS/OrchardCore","slug":"the-clamav-antivirus-scanner-timed-out-while-scanning","errorCode":null,"errorMessage":"The ClamAV antivirus scanner timed out while scanning '{context.FileName}'.","messagePattern":"The ClamAV antivirus scanner timed out while scanning '(.+?)'\\.","errorType":"exception","errorClass":"AntivirusScanningException","httpStatus":null,"severity":"error","filePath":"src/OrchardCore.Modules/OrchardCore.Antivirus/ClamAV/ClamAvFileEventHandler.cs","lineNumber":66,"sourceCode":"            if (TryCreateFailureResult(context, scanStream, response) is { } failureResult)\n            {\n                return failureResult;\n            }\n\n            scanStream.Position = 0;\n\n            return FileCreatingResult.Success(scanStream);\n        }\n        catch (OperationCanceledException exception)\n        {\n            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            }","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/OrchardCMS/OrchardCore/blob/4306c0717fe573f6fca1b4955909ddab6a192807/src/OrchardCore.Modules/OrchardCore.Antivirus/ClamAV/ClamAvFileEventHandler.cs#L48-L84","documentation":"OrchardCore's ClamAV antivirus module scans every uploaded file through a ClamAV INSTREAM connection. When the scan is cancelled or exceeds the configured timeouts, the OperationCanceledException is caught in CreatingAsync and rethrown as an AntivirusScanningException carrying this message, after logging the original exception.","triggerScenarios":"Uploading a file triggers CreatingAsync; the ClamAV ScanAsync call exceeds ConnectTimeoutSeconds/TransferTimeoutSeconds, or the CancellationToken fires (request abort, server shutdown) mid-scan.","commonSituations":"Large uploads over slow links to a remote clamd, undersized timeout settings, an overloaded or under-provisioned ClamAV daemon, or clients cancelling uploads.","solutions":["Increase ClamAV ConnectTimeoutSeconds/TransferTimeoutSeconds in the antivirus options to cover your largest uploads.","Verify the clamd daemon is healthy and not overloaded (check clamd logs, MaxScanSize, CPU).","Reduce upload size limits or move ClamAV closer to the app to cut scan latency.","Implement client retry with backoff for uploads that fail due to transient timeout."],"exampleFix":"// before\nservices.AddClamAv(options => { options.Host = \"clamd\"; options.Port = 3310; });\n// after\nservices.AddClamAv(options => { options.Host = \"clamd\"; options.Port = 3310; options.ConnectTimeoutSeconds = 30; options.TransferTimeoutSeconds = 300; });","handlingStrategy":"try-catch","validationCode":"// before upload, ensure timeouts cover the file size\nif (file.Length > estimatedMaxBytesPerSecond * options.TransferTimeoutSeconds)\n{\n    // warn: scan likely to time out\n}","typeGuard":null,"tryCatchPattern":"try\n{\n    await UploadFileAsync(stream);\n}\ncatch (AntivirusScanningException ex) when (ex.InnerException is OperationCanceledException)\n{\n    logger.LogWarning(ex, \"Antivirus scan timed out; retry or raise timeouts.\");\n}","preventionTips":["Size ConnectTimeoutSeconds/TransferTimeoutSeconds to your largest allowed upload.","Keep clamd on a low-latency network path from the app.","Monitor clamd load and scan durations; alert on approaching timeouts.","Cap upload size limits consistently with scan timeouts."],"tags":["clamav","antivirus","timeout","file-upload"],"backgroundTag":"request-timeout","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"}