-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hotfix: Virus Scanning - Not functioning PROD (Test as well) #3825
Comments
The error was possible to be reproducible in the local development machine using 17Kb files. Any file larger than 16Kb causes the error, which means that the default chunk size allocated for the stream buffer was exceeded. The readable streams have two reading modes: [flowing and paused](https://nodejs.org/api/stream.html#two-reading-modes). The connection to `clamav` server was open but was not receiving data for certain files, which led to the timeout. When the `passthroughStream.resume();` was added it resulted in the data being send immediately. The `passthroughStream.readableFlowing` was defined as null, which means the below ([source](https://nodejs.org/api/stream.html#three-states)) - readable.readableFlowing === null - readable.readableFlowing === false - readable.readableFlowing === true In the [example from the clamscan](passthroughStream) package, the `passthrough` stream is piped to an output stream which also resumes the stream, as mentioned below. > All [Readable](https://nodejs.org/api/stream.html#class-streamreadable) streams begin in paused mode but can be switched to flowing mode in one of the following ways: > > Adding a ['data'](https://nodejs.org/api/stream.html#event-data) event handler. > Calling the [stream.resume()](https://nodejs.org/api/stream.html#readableresume) method. > Calling the [stream.pipe()](https://nodejs.org/api/stream.html#readablepipedestination-options) method to send the data to a [Writable](https://nodejs.org/api/stream.html#class-streamwritable). Local test results: - a 4MB file is processed in less than 3 seconds. - a 15 MB file is processed in approximately 15 seconds. - queued 50 files of 15 MB and it had a total processing time of 15 minutes with no errors. No timeouts adjusted in this PR and we may not adjust any if the tests on Openshift go well for this change. The target of this change is to fix the current production issue only.
The error was possible to be reproducible in the local development machine using 17Kb files. Any file larger than 16Kb causes the error, which means that the default chunk size allocated for the stream buffer was exceeded. The readable streams have two reading modes: [flowing and paused](https://nodejs.org/api/stream.html#two-reading-modes). The connection to `clamav` server was open but was not receiving data for certain files, which led to the timeout. When the `passthroughStream.resume();` was added it resulted in the data being send immediately. The `passthroughStream.readableFlowing` was defined as null, which means the below ([source](https://nodejs.org/api/stream.html#three-states)) - readable.readableFlowing === null - readable.readableFlowing === false - readable.readableFlowing === true In the [example from the clamscan](passthroughStream) package, the `passthrough` stream is piped to an output stream which also resumes the stream, as mentioned below. > All [Readable](https://nodejs.org/api/stream.html#class-streamreadable) streams begin in paused mode but can be switched to flowing mode in one of the following ways: > > Adding a ['data'](https://nodejs.org/api/stream.html#event-data) event handler. > Calling the [stream.resume()](https://nodejs.org/api/stream.html#readableresume) method. > Calling the [stream.pipe()](https://nodejs.org/api/stream.html#readablepipedestination-options) method to send the data to a [Writable](https://nodejs.org/api/stream.html#class-streamwritable). Local test results: - a 4MB file is processed in less than 3 seconds. - a 15 MB file is processed in approximately 15 seconds. - queued 50 files of 15 MB and it had a total processing time of 15 minutes with no errors. No timeouts adjusted in this PR and we may not adjust any if the tests on Openshift go well for this change. The target of this change is to fix the current production issue only.
## Cherry pick commits The following commits are cherry picked and committed into `file-integration-fix/cherry-pick-branch` branch from `main` branch. - #3833 - SIN Validation - Gender Field Limit - Commit:8040205 - SHA: 8040205 - #3831 - SINF restriction bridge mapping and rename to SINR - Commit:3ed8c2e - SHA: 3ed8c2e - #3825 - Virus Scanning - Not functioning PROD - Commit: 5bb5050 - SHA: 5bb5050 - #3745 - Modify process that reads SIN & CRA verification response files - Commit: 20fcda4 - SHA: 20fcda4
When starting a socket to send a file content to `clamav` using the passthrough and no content is sent, the connection stays open for an indefinite amount of time (over 5 minutes). Changed queue-consumers to throw an error and remove the job, **same behavior when the file is not found**. _We can have a separate ticket to apply validation for the file upload to avoid accepting empty files, but I considered it outside this hotfix issue._ ClamAV debug log when a empty file is send for scanning. ``` 2024-10-31 08:32:55 node-clam: Initially testing socket/tcp connection to clamscan server. 2024-10-31 08:32:55 node-clam: Attempting to establish socket/TCP connection for "_ping" 2024-10-31 08:32:55 node-clam: using remote server: 172.18.0.6:3310 2024-10-31 08:32:55 node-clam: Established connection to clamscan server! 2024-10-31 08:32:55 node-clam: PONG! 2024-10-31 08:32:55 node-clam: Established connection to clamscan server! 2024-10-31 08:32:55 node-clam: Done with the full pipeline. 2024-10-31 08:32:55 node-clam: Socket/Host connection closed. 2024-10-31 08:33:00 node-clam: ClamAV has been scanning for 5 seconds... ... 2024-10-31 08:35:25 node-clam: ClamAV has been scanning for 150 seconds... ... 2024-10-31 08:45:30 node-clam: ClamAV has been scanning for 755 seconds... ... ```
@Joshua-Lakusta @CarlyCotton, while testing this (now or in the future), please ensure that files with content greater than 16Kb are used. Files with less than 16Kb would work even before this fix, which would lead to a false positive. Files with no content will not be scanned right now. As per the conversation on Teams chat.
|
Issue Description
File uploads are not being scanned - hanging in pending.
Acceptance Criteria
Logs from PROD:
![image.png](https://camo.githubusercontent.com/8050af5e2b6f7b8a2864dfa9e914877b5b95056418464e8b94dc2817d9743be6/68747470733a2f2f6170692e7a656e6875622e636f6d2f617474616368656446696c65732f65794a66636d467062484d694f6e73696257567a6332466e5a534936496b4a42614842424e544633516e633950534973496d563463434936626e56736243776963485679496a6f69596d7876596c39705a434a3966513d3d2d2d336433643262333633643032366434653731623736323435373565386434333535343766663432302f696d6167652e706e67)
Additional Context
The text was updated successfully, but these errors were encountered: