clamscan
clamscan copied to clipboard
fix: handle ping timeout error after client created
Fix for timeout error on ping request using remote server.
Explanation
The timeout error is thrown after the client is created and the promise is neither resolved nor rejected.
To fix this, the ping method should handle the timeout error after the client is created.
Test scenario
First, run a clamav server.
services:
clamav:
image: tiredofit/clamav
ports:
- 3310:3310
volumes:
- clamav_data:/data
- clamav_logs:/logs
volumes:
clamav_data:
clamav_logs:
Then, block traffic for clamav server.
sudo iptables -D INPUT -p tcp --dport 3310 -j DROP
sudo iptables -D OUTPUT -p tcp --dport 3310 -j DROP
And finally, try to connect to clamav server.
try {
const client = await new NodeClam().init({
clamdscan: {
host: 'localhost',
port: 3310,
timeout: 2_000,
},
preference: 'clamdscan',
});
} catch(err) {
console.error('Failed to create ClamAV client', err);
}
A suggestion to improve ping method. It would be possible to add a config property pingTimeout to use it in ping requests. This way, there will be two timeouts for scan and ping requests.
Thank you for your contribution!
We need to figure out a way to make a working test as part of our test suite before this can be merged in. Give it a go and see if you can get a test written for this scenario.
Also, documentation would need to be updated if you want to add a pingTimeout config property. How would the pingTimeout configuration be implemented?
Thank you for your contribution!
We need to figure out a way to make a working test as part of our test suite before this can be merged in. Give it a go and see if you can get a test written for this scenario.
Of course, I will try to add a test for timeout errors.
Also, documentation would need to be updated if you want to add a
pingTimeoutconfig property. How would thepingTimeoutconfiguration be implemented?
Ok, I will update the docs as well. I was thinking about adding pingTimeout to the init options and then use it as param in _initSocket.
That all sounds great! Looking forward to seeing the feature added!