E
everttimmer
Guest
From a webservice i do a virusscan on uploaded file using a command line utility of the virus scanner in use.
It is possible to upload multiple files in one request and the files will be scanned one-by-one, sequentially.
The code i am using is the following:
using (Process process = new Process
{
StartInfo = new ProcessStartInfo(SCANEXE)
{
Arguments = $"\"{filePath}\" /some-switch /another-switch",
CreateNoWindow = true,
ErrorDialog = false,
WindowStyle = ProcessWindowStyle.Hidden,
UseShellExecute = false
}
})
{
process.Start();
if (process.WaitForExit(timeoutInMs))
process.WaitForExit();
if (process.HasExited)
{
switch (process.ExitCode)
{
case 0:
return new ScanResult
{
ExitCode = process.ExitCode,
State = ScanResult.States.FILEISCLEAN
};
case 1:
case 50:
return new ScanResult
{
ExitCode = process.ExitCode,
State = ScanResult.States.FILEISDIRTY
};
case 10:
case 100:
return new ScanResult
{
ExitCode = process.ExitCode,
State = ScanResult.States.SCANERROR
};
default:
return new ScanResult
{
ExitCode = process.ExitCode,
State = ScanResult.States.SCANERROR
};
}
}
process.Kill();
return new ScanResult
{
State = ScanResult.States.SCANTIMEOUT
};
}
What happens is that in approximately 5% of all scan attempts, Process.Start fails with an "Access Denied". The behavior is completely random, and has nothing to do with file beeing scanned. The same file will be scanned correctly in a subsequent try.
Wrapping the proces in a using statement as shown above (it was not, originally) improves the situation but does not completely fix the issue. (from 5% to approx. 1%)
It appeared to me like a timing issue so I did put in a Thread.Sleep(100) to get some time between process ending and next process starting. Without any success...
Does somebody have any clue ?
I am running out of ideas here...
Maybe worth noticing:
This problem magically started 1 day after a in-place-upgrade from the server from W2008 to W2012.
Continue reading...
It is possible to upload multiple files in one request and the files will be scanned one-by-one, sequentially.
The code i am using is the following:
using (Process process = new Process
{
StartInfo = new ProcessStartInfo(SCANEXE)
{
Arguments = $"\"{filePath}\" /some-switch /another-switch",
CreateNoWindow = true,
ErrorDialog = false,
WindowStyle = ProcessWindowStyle.Hidden,
UseShellExecute = false
}
})
{
process.Start();
if (process.WaitForExit(timeoutInMs))
process.WaitForExit();
if (process.HasExited)
{
switch (process.ExitCode)
{
case 0:
return new ScanResult
{
ExitCode = process.ExitCode,
State = ScanResult.States.FILEISCLEAN
};
case 1:
case 50:
return new ScanResult
{
ExitCode = process.ExitCode,
State = ScanResult.States.FILEISDIRTY
};
case 10:
case 100:
return new ScanResult
{
ExitCode = process.ExitCode,
State = ScanResult.States.SCANERROR
};
default:
return new ScanResult
{
ExitCode = process.ExitCode,
State = ScanResult.States.SCANERROR
};
}
}
process.Kill();
return new ScanResult
{
State = ScanResult.States.SCANTIMEOUT
};
}
What happens is that in approximately 5% of all scan attempts, Process.Start fails with an "Access Denied". The behavior is completely random, and has nothing to do with file beeing scanned. The same file will be scanned correctly in a subsequent try.
Wrapping the proces in a using statement as shown above (it was not, originally) improves the situation but does not completely fix the issue. (from 5% to approx. 1%)
It appeared to me like a timing issue so I did put in a Thread.Sleep(100) to get some time between process ending and next process starting. Without any success...
Does somebody have any clue ?
I am running out of ideas here...
Maybe worth noticing:
This problem magically started 1 day after a in-place-upgrade from the server from W2008 to W2012.
Continue reading...