Skip to content
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

Receiving null response from ScanFile #113

Closed
AishwaryaKotla opened this issue Jun 13, 2023 · 2 comments
Closed

Receiving null response from ScanFile #113

AishwaryaKotla opened this issue Jun 13, 2023 · 2 comments
Labels
edge case When there may be a bug but its in a rare or hard-to-replicate edge case.

Comments

@AishwaryaKotla
Copy link

AishwaryaKotla commented Jun 13, 2023

Team, I am receiving all the attributes as null in the response from the ScanFile method. Where as sending request via brew client to my server, i am getting a valid response. Could someone please help me on this. It might be some issue related to library or my configuration.

FYI: I am getting a valid response, when I use debugger mode and not in a normal mode. The configuration below is in nestjs.

package.json

"clamscan": "^2.1.2",
"@types/clamscan": "^2.0.4",

service.ts

import NodeClam = require('clamscan');

async scanFile(filePath: string) {
    try {
        const clamScan = new NodeClam().init({
            debugMode: true,
            clamdscan: {
                host: 'xxx',
                port: xxx,
                localFallback: false,
            },
        });
        const response = await (await clamScan).isInfected(filePath);
        return response;
    } catch (error) {
         console.error('Error occurred while scanning the file:', error);
         return false;
    }
}
  
async scanForVirus(excel: Express.Multer.File) {
    const result = await this.scanFile(excel.path);
    console.log(await result);
}

The result I am receiving is the below

node-clam: File may be INFECTED!
{
    file: null,
    isInfected: null,
    viruses: [],
    resultString: '',
    timeout: false
}

I see the below response using debugger when i tried to debug using breakpoints

{
    file: null,
    isInfected: false,
    viruses: [],
    resultString: 'OK',
    timeout: false
}

This might be happening due to the asynchronous operations running out of time in normal mode, where as in debug mode it might be having enough time to execute in between running the break points.

Could someone please let me know what might be causing the issue. Thanks in Advance.

@vsawant1608
Copy link

Were you able to get the fix? I am also getting same error and trying to fix it.

@kylefarris
Copy link
Owner

I know it's been a while but I've got a couple things I noticed...

  1. You're doing import NodeClam = require('clamscan'); when it should be import NodeClam from 'clamscan'
  2. You should really just await the response from init instead of doing await (await clamScan).isInfected() -- that's just confusing/funky.

That being said, is your scanning service local or remote? If it's remote, it may be suffering from a timeout. You can increase the timeout with an optional config (timeout). The default is already 60 seconds, though. If you scanning very large files, you may need more. I suspect that's not the issue either, though, if you're thinking the difference in debugging or not is the difference in the timing.

All the tests seem to be working out just fine and I have several production servers running Ubuntu and AlmaLinux (RIP) that don't have this issue as well as my personal Mac for development. It's likely a code or configuration issue.

@kylefarris kylefarris added the edge case When there may be a bug but its in a rare or hard-to-replicate edge case. label Mar 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
edge case When there may be a bug but its in a rare or hard-to-replicate edge case.
Projects
None yet
Development

No branches or pull requests

3 participants