Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Virus scanners locking and deleting temporary files - best way to cope with them?

My application deals with e-mails coming from different sources, e.g. Outlook and IMAP mailboxes. Before parsing them, I write them to the temporary directory (keeping them in memory is not an option). While parsing, I might be writing attachments to the temp directory (for example, if they are too large to keep in memory or for full-text extraction).

But in the wild, two things happen that seemed very strange in the first place but could all be traced back to virus scanner behaviour:

  • I'm sometimes unable to open files which I've written myself a few milliseconds ago. They are obviously locked by virus scanners to ensure that they are clean. I get an Exception.

  • If files are considered dangerous by the virus scanner, it deletes them at some point of time.

To cope with this behaviour, I've written a few methods that try again if open fails or do some checks if files exist, but I'm unable to use them in every part of the application (3rd party code, for example filters), so things got better, but not 100% perfect and my source code looks ugly in parts because of this.

How do you cope with virus scanners?

like image 670
Stefan Schultze Avatar asked Oct 18 '08 10:10

Stefan Schultze


1 Answers

If changing Virus scanner configuration is not the ideal option for you. Could you keep the file open from it's creation up to the end of your process? If you got an handle on the file, it will not be available for the Virus scanner.

like image 77
Hapkido Avatar answered Oct 03 '22 20:10

Hapkido