Bug 790598

Summary: Drift detection fails for whole directory if special-file is present
Product: [Other] RHQ Project Reporter: Jay Shaughnessy <jshaughn>
Component: driftAssignee: Jay Shaughnessy <jshaughn>
Status: CLOSED CURRENTRELEASE QA Contact: Mike Foley <mfoley>
Severity: urgent Docs Contact:
Priority: high    
Version: 4.2CC: hrupp, loleary
Target Milestone: ---   
Target Release: RHQ 4.3.0   
Hardware: All   
OS: All   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: 789454 Environment:
Last Closed: 2013-09-01 10:16:41 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On: 789454    
Bug Blocks: 728579    

Description Jay Shaughnessy 2012-02-14 22:09:07 UTC
+++ This bug was initially created as a clone of Bug #789454 +++

DriftDetection fails if eht directory to be monitored e.g. contains a unix domain socket (see stack trace below) 

org.rhq.core.pc.drift.DriftDetector#doDirectoryScan

basically does
       for (File dir : getScanDirectories(basedir, includes)) {
            forEachFile(dir, new FilterFileVisitor(basedir, includes, excludes, new FileVisitor() {
                @Override
                public void visit(File file) {
                    try {
                     ... work_on_file... <<--- fails for socket, see below
                    } catch (IOException e) {
                        throw new DriftDetectionException(
                            "An error occurred while generating a coverage change set for " + schedule, e);
                    }
}

So if the _work_on_file part is throwing an IOException as it does for a socket, the catch-block is re-throwing that as DriftDetectionException and throwing out of  the whole set of loops, basically ignoring all files that are still to be processed. 
As the postgres socket name starts with a dot, it is sorted early in the list, so that it basically breaks drift detection for the directory completely.

While /tmp may be a corner case for drift detection, unix domain sockets (and other kinds of special files) can show up in all directories.

2012-02-10 20:36:59,963 ERROR [pool-3-thread-1] (rhq.core.pc.drift.DriftDetector)- Drift detection failed: An error occurred while generating a coverage change set for DriftDetectionSchedule[resourceId: 10001, driftDefinitionId: 10001, driftDefinitionName: fosdem]
org.rhq.core.pc.drift.DriftDetectionException: An error occurred while generating a coverage change set for DriftDetectionSchedule[resourceId: 10001, driftDefinitionId: 10001, driftDefinitionName: fosdem]
	at org.rhq.core.pc.drift.DriftDetector$2.visit(DriftDetector.java:667)
	at org.rhq.core.pc.drift.FilterFileVisitor.visit(FilterFileVisitor.java:136)
	at org.rhq.core.util.file.FileUtil.forEachFile(FileUtil.java:434)
	at org.rhq.core.pc.drift.DriftDetector.doDirectoryScan(DriftDetector.java:649)
	at org.rhq.core.pc.drift.DriftDetector.generateSnapshot(DriftDetector.java:627)
	at org.rhq.core.pc.drift.DriftDetector.run(DriftDetector.java:139)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
	at java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:317)
	at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:150)
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$101(ScheduledThreadPoolExecutor.java:98)
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.runPeriodic(ScheduledThreadPoolExecutor.java:180)
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:204)
	at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
	at java.lang.Thread.run(Thread.java:680)
Caused by: java.io.FileNotFoundException: /tmp/.s.PGSQL.5432 (Operation not supported on socket)
	at java.io.FileInputStream.open(Native Method)

--- Additional comment from mfoley on 2012-02-10 14:57:29 EST ---

when verifying ... please also try edge cases such as:

links
named pipes
sockets
block devices

see section 3-1 in this document:
http://tldp.org/LDP/intro-linux/html/sect_03_01.html

--- Additional comment from mfoley on 2012-02-13 11:51:33 EST ---

when verifying, please also (re) verify file permission testcases ...particularly files which the agent does not have permission for

--- Additional comment from hrupp on 2012-02-14 11:17:12 EST ---

missing lines of the stack trace

Caused by: java.io.FileNotFoundException: /tmp/.s.PGSQL.5432 (Operation not supported on socket)
	at java.io.FileInputStream.open(Native Method)
	at java.io.FileInputStream.<init>(FileInputStream.java:120)
	at org.rhq.core.util.MessageDigestGenerator.calcDigest(MessageDigestGenerator.java:255)
	at org.rhq.core.util.MessageDigestGenerator.calcDigestString(MessageDigestGenerator.java:291)
	at org.rhq.core.pc.drift.DriftDetector.sha256(DriftDetector.java:689)
	at org.rhq.core.pc.drift.DriftDetector.access$200(DriftDetector.java:57)
	at org.rhq.core.pc.drift.DriftDetector$2.visit(DriftDetector.java:662)

--- Additional comment from jshaughn on 2012-02-14 17:08:31 EST ---


release/3.0.x commit: f55c68ee2db419cbbe2daef2f7721a7c68279039

 File.canRead() returning true means that the process has read access to
 a file, it is a security check. It does not mean that the file can be
 parsed as a Stream.  In particular, FileInputStream(File) can throw
 FileNotFoundException on a file it can't actually handle, like a
 socket file.

 I added more protection for this situation, for files which drift monitoring
 can not and should not be performed.  They will be skipped (and logged in
 debug).  Moreover, taking Heiko's suggestion, don't fail drift detection
 due to a problematic file, even if the problem is unexpected.

Comment 1 Jay Shaughnessy 2012-02-14 22:14:34 UTC
master commit: a45b19cfdf4ef57fd33d620117bcfc4807531899

Comment 2 Heiko W. Rupp 2013-09-01 10:16:41 UTC
Bulk closing of items that are on_qa and in old RHQ releases, which are out for a long time and where the issue has not been re-opened since.