{"record":{"id":"f4b93f6d01168137","repo":"OrchardCMS/OrchardCore","slug":"the-clamav-antivirus-scanner-failed-while-scanning-context","errorCode":null,"errorMessage":"The ClamAV antivirus scanner failed while scanning '{context.FileName}'.","messagePattern":"The ClamAV antivirus scanner failed while scanning '(.+?)'\\.","errorType":"exception","errorClass":"AntivirusScanningException","httpStatus":null,"severity":"error","filePath":"src/OrchardCore.Modules/OrchardCore.Antivirus/ClamAV/ClamAvFileEventHandler.cs","lineNumber":88,"sourceCode":"            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            }\n\n            throw;\n        }\n    }\n\n    public Task CreatedAsync(IFileStoreEntry fileInfo, CancellationToken cancellationToken = default)\n        => Task.CompletedTask;\n\n    private async Task<Stream> CreateSeekableStreamAsync(Stream stream, CancellationToken cancellationToken)\n    {\n        var tempFilePath = _tempDirectoryProvider.GetTempFileName();","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/OrchardCMS/OrchardCore/blob/4306c0717fe573f6fca1b4955909ddab6a192807/src/OrchardCore.Modules/OrchardCore.Antivirus/ClamAV/ClamAvFileEventHandler.cs#L70-L106","documentation":"IOException during the ClamAV INSTREAM scan is caught in CreatingAsync and rethrown as an AntivirusScanningException with this generic failure message. It indicates a stream/IO failure while transferring the file to or reading the result from the ClamAV daemon.","triggerScenarios":"ScanAsync raises IOException — e.g. the clamd connection drops mid-transfer, the temp seekable stream write/read fails, or the socket stream is broken while scanning context.FileName.","commonSituations":"clamd restarting mid-scan, connection reset by clamd's StreamMaxLength limit, disk issues with the temp file, flaky network between app and daemon.","solutions":["Inspect the inner exception (logged via LogError) to find the underlying IO cause.","Check clamd's StreamMaxLength / TCPSocket settings — oversized streams can be dropped.","Ensure clamd is stable (uptime, memory) and not being restarted mid-upload.","Retry the upload; if persistent, check disk space and temp directory health on the app host."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try\n{\n    await UploadFileAsync(stream);\n}\ncatch (AntivirusScanningException ex) when (ex.InnerException is IOException)\n{\n    logger.LogError(ex, \"IO failure during AV scan; retrying may help.\");\n    // retry once, then fail the upload cleanly\n}","preventionTips":["Set clamd StreamMaxLength above the app's max upload size.","Monitor clamd restarts and connection resets.","Keep adequate disk space for temp seekable streams.","Avoid proxies/load balancers in the clamd socket path."],"tags":["clamav","io","file-upload"],"backgroundTag":"broken-pipe","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"}