You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by bu...@apache.org on 2008/09/11 23:19:36 UTC

DO NOT REPLY [Bug 45786] New: ANT and NFS, Delete task - "Unable to delete directory"

https://issues.apache.org/bugzilla/show_bug.cgi?id=45786

           Summary: ANT and NFS, Delete task - "Unable to delete directory"
           Product: Ant
           Version: unspecified
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Core tasks
        AssignedTo: notifications@ant.apache.org
        ReportedBy: leszek.szarlej@sabre.com


Hello,

I am experiencing problem due to Ant’s “unable to delete directory”
error.

I am running builds on NAS storage (NFS) inside ClearCase snapshot view
directory on RedHat 5 OS.

Ant’s delete task fails because directory is not empty, however it doesn’t
contain any file after the build has failed:



System calls with exception ENOTEMPTY:

14939 unlink("/nfs_mount/project1/views/test1/vobs/test1/bb/Deploy") = -1
EISDIR (Is a directory)

14939 rmdir("/nfs_mount/project1/views/test1/vobs/test1/bb/Deploy") = -1
ENOTEMPTY (Directory not empty)

14939 gettimeofday({1220420751, 309536}, NULL) 



I modified Ant’s Delete.java source, adding a line that drops content of a
directory before delete attempt.

Ant’s output confirmed our predictions (hidden .nfsxxxxx file)



2008-09-03 08:36:12,495 [Thread-14] INFO  ScriptRunner     -    [delete] ###
Content of /nfs_mount/project1/views/test1/vobs/test1/bb/Deploy:
[.nfs0000000001291e4e000000c5]

2008-09-03 08:36:11,881 [Thread-13] WARN  ScriptRunner     -
/nfs_mount/project1/views/test1/vobs/test1/bb/base/build.xml:315: Unable to
delete directory /nfs_mount/project1/views/test1/vobs/test1/bb/Deploy



Because the hidden .nfs file doesn’t exist when build crashes, I told ant to
sleep 6 minutes after first failed attempt of deleting directory. When ant
stopped streaming messages I found what is the directory that it couldn’t
delete:

[delete] ### Content of /nfs_mount/project1/views/test1/vobs/test1/bb/Deploy:
[.nfs0000000001dfe6d2000000c9]



While ant was sleeping I checked that directory:

bash-3.2# ls -la /nfs_mount/project1/views/test1/vobs/test1/bb/Deploy

total 2168

drwxr-xr-x  2 cimaster wmbs    4096 Sep  3  2008 .

drwxr-xr-x 54 cimaster wmbs    4096 Sep  3  2008 ..

-rw-r--r--  1 cimaster wmbs 2203627 Sep  3  2008 .nfs0000000001dfe6d2000000c9



..I checked what process has this file opened:



bash-3.2# lsof
/nfs_mount/project1/views/test1/vobs/test1/bb/Deploy/.nfs0000000001dfe6d2000000c9

COMMAND   PID     USER   FD   TYPE DEVICE    SIZE     NODE NAME

java    17808 cimaster  mem    REG   0,30 2203627 31450834
/nfs_mount/project1/views/test1/vobs/test1/bb/Deploy/.nfs0000000001dfe6d2000000c9

java    17808 cimaster   42r   REG   0,30 2203627 31450834
/nfs_mount/project1/views/test1/vobs/test1/bb/Deploy/.nfs0000000001dfe6d2000000c9



and found process number 17808

cimaster 17808 17807 10 15:30 ?        00:00:25
/usr/java/jdk1.6.0_07/jre/bin/java -Xms512m -Xmx1024m -XX:MaxPermSize=256m
-classpath /tmp/cc/ant/lib/ant-launcher.jar -Dant.home=/tmp/cc/ant
-Dant.library.dir=/tmp/cc/ant/lib org.apache.tools.ant.launch.Launcher -cp
:/lib/jdepend-2.9/lib/jdepend-2.9.jar:/lib/jdepend-2.9/lib/jdepend-2.9.jar:/lib/jdepend-2.9/lib/jdepend-2.9.jar
-v -logger net.sourceforge.cruisecontrol.builders.AntProgressLogger -listener
org.apache.tools.ant.XmlLogger -DXmlLogger.file=log.xml -lib
/tmp/cc/lib/cruisecontrol-antprogresslogger.jar
-Dcclastbuildtimestamp=20080901000000 -Dcvstimestamp=2008-09-03 20:30:39 GMT
-Dbuildforced=true -Dcclastgoodbuildtimestamp=20080901000000
-Dcctimestamp=20080903153039 -Dclearcasenow=03-September-2008.15:30:39
-Dlabel=build.1 -Dprojectname=Merchant_Svcs
-Dclearcaselastbuild=01-September-2008.00:00:00 -Dlastbuildsuccessful=false
-buildfile /nfs_mount/project1/views/test1/vobs/test1/bb/build.xml target



so it is an ant process, it means that ant keeps handle do this file itself and
that is why it can’t delete it ?

If it is true, this file should disappear when ant process crashes after second
deletion attempt. I waited for 6 minutes period to end. When ant crashed, I
listed content of that directory:

bash-3.2$ ls -la /nfs_mount/project1/views/test1/vobs/test1/bb/Deploy

total 8

drwxr-xr-x  2 cimaster wmbs 4096 Sep  3  2008 .

drwxr-xr-x 54 cimaster wmbs 4096 Sep  3  2008 ..



The file doesn’t exist anymore. Looking on hidden .nfs file size, I found
that this file is a copy of some jar file (which is deleted) inside that
directory. 



Tested on many Ant versions and many jdk versions. When I execute build on
local storage, build goes fine. Thanks for any help in debugging this issue.



Leszek


-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

DO NOT REPLY [Bug 45786] ANT and NFS, Delete task - "Unable to delete directory"

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=45786

--- Comment #5 from Stefan Bodewig <bo...@apache.org> 2011-09-29 13:42:11 UTC ---
could anybody please give svn revision 1177305 a try?

<delete> has a new performGCOnFailedDelete that defaults to true on Windows and
may help in the NFS case when set to true as well.

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

DO NOT REPLY [Bug 45786] ANT and NFS, Delete task - "Unable to delete directory"

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=45786


Stefan Bodewig <bo...@apache.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |NEEDINFO




-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

DO NOT REPLY [Bug 45786] ANT and NFS, Delete task - "Unable to delete directory"

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=45786

Stefan Bodewig <bo...@apache.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED

--- Comment #6 from Stefan Bodewig <bo...@apache.org> 2012-02-01 12:42:05 UTC ---
I'll simply assume performGCOnFailedDelete works.  Please reopen if it doesn't
help.

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

DO NOT REPLY [Bug 45786] ANT and NFS, Delete task - "Unable to delete directory"

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=45786

Jesse Glick <jg...@netbeans.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jglick@netbeans.org
   Target Milestone|---                         |1.8.3

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

DO NOT REPLY [Bug 45786] ANT and NFS, Delete task - "Unable to delete directory"

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=45786





--- Comment #1 from Stefan Bodewig <bo...@apache.org>  2008-09-16 01:50:02 PST ---
can you extract a simple test that fails but (preferable) doesn't involve
clearcase?

I don't think Ant's Java code created that file and much less expect it to keep
the file open, but I'm neither familiar with clearcase nor the way Ant
interacts with it.

When there is the .nfs* file Ant would probably try to delete it but fail (is
there any log talking about that?) if not, then File.list() on the directory
doesn't mention the file at all.


-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

DO NOT REPLY [Bug 45786] ANT and NFS, Delete task - "Unable to delete directory"

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=45786

John McNally <jm...@apache.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEEDINFO                    |NEW
                 CC|                            |jmcnally@apache.org

--- Comment #3 from John McNally <jm...@apache.org> 2011-09-28 22:11:56 UTC ---
The problem with deleting directories on NFS is likely not specific to ant. The
following code will exhibit the problem

public static boolean deleteDir(File dir) {

if (dir.isDirectory()) {
    String[] children = dir.list();

    for (int i = 0; i < children.length; i++) {
        boolean success = deleteDir(new File(dir, children[i]));
        if (!success) {  
            return false;
        }
    }
}

return dir.delete(); // this will not delete a directory containing .nfs files

}

I've found that replacing the return statement above with the following code
allows the delete to proceed to completion:

boolean isDeleted = dir.delete();
if (!isDeleted && dir.exists()) {
    // Directories mounted on NFS volumes may have lingering .nfsXXXX files
    // if no streams are open, it is likely from stale objects
    System.gc();
    try {
        Thread.sleep(100);
    } catch (InterruptedException e) {
        //ignored
    }
    isDeleted = dir.delete();
}
return isDeleted;


Not the most satisfying solution, but it works.  In this case there doesn't
seem to be any code directly making use of the files which were deleted.  But
maybe the dir.list() code used to loop over and clear the directory has some
stale objects which must be GC'ed before the directory will delete.  The slight
delay also improves the likelihood the .nfs files are removed, but is not a
substitute for the GC.

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

DO NOT REPLY [Bug 45786] ANT and NFS, Delete task - "Unable to delete directory"

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=45786

--- Comment #4 from Stefan Bodewig <bo...@apache.org> 2011-09-29 13:01:05 UTC ---
This looks a lot like the code in FileUtils#tryHardToDelete, should be possible
to refactor all code that deletes trees to use that.  I'll give it a try.

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

DO NOT REPLY [Bug 45786] ANT and NFS, Delete task - "Unable to delete directory"

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=45786





--- Comment #2 from J.M. (Martijn) Kruithof <jk...@apache.org>  2008-10-19 04:21:53 PST ---
This is general behavior of NFS based file systems, under normal unix
filesystems a file is referenced by either the file system or by an process or
both. The reference from the file system can be removed, the reference to the
already deleted file from the running process remains open. (This process can
still read and/or write this file.) In case of an NFS file system a dummy entry
is created in the same directory. The open process has no handles on the
machine the file is located. To avoid the file being deleted while handles are
still open this .nfs entry is created. (removing this .nfs file, will just
cause a new .nfs file to be created as long as the process is running.)

The solution therefore is to close the open file handle to this jar file before
trying to delete the directory.

- When / why is this jar file opened ant?

- When should this jar file be released by ant?

In case the first question is answered with from the start (classpath provided
to ant when starting) there is nothing we can do.
In case the jar file is opened later we can see if it is possible to close the
classloader used to open the jar file. This may lead to the possible to delete
the file.


-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

DO NOT REPLY [Bug 45786] ANT and NFS, Delete task - "Unable to delete directory"

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=45786


Leszek <le...@sabre.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |major




-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.