You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@activemq.apache.org by gaohoward <gi...@git.apache.org> on 2018/12/19 15:30:19 UTC

[GitHub] activemq-artemis pull request #2473: ARTEMIS-1058 Jars in web tmp dir locked...

GitHub user gaohoward opened a pull request:

    https://github.com/apache/activemq-artemis/pull/2473

    ARTEMIS-1058 Jars in web tmp dir locked on Windows

    Because Sun's URLClassLoader never closes it's jar file handles
    Jetty doesn't cleanup is temp web dir after Artemis broker shut
    down normally on Windows.
    
    To work around this a new process is forked before broker VM
    exits to clean up the tmp dir if they are not deleted. The
    new process out lives the main VM so that those jar's handles
    are released and the temp dir can be cleaned up.

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/gaohoward/activemq-artemis b_522

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/activemq-artemis/pull/2473.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #2473
    
----
commit af27cc96555390ec63d35e9c157aa658bde60797
Author: Howard Gao <ho...@...>
Date:   2018-12-19T14:54:59Z

    ARTEMIS-1058 Jars in web tmp dir locked on Windows
    
    Because Sun's URLClassLoader never closes it's jar file handles
    Jetty doesn't cleanup is temp web dir after Artemis broker shut
    down normally on Windows.
    
    To work around this a new process is forked before broker VM
    exits to clean up the tmp dir if they are not deleted. The
    new process out lives the main VM so that those jar's handles
    are released and the temp dir can be cleaned up.

----


---

[GitHub] activemq-artemis issue #2473: ARTEMIS-1058 Jars in web tmp dir locked on Win...

Posted by gaohoward <gi...@git.apache.org>.
Github user gaohoward commented on the issue:

    https://github.com/apache/activemq-artemis/pull/2473
  
    manually tested on Windows 7 64bit and Windows 10 64bit.


---

[GitHub] activemq-artemis issue #2473: ARTEMIS-1058 Jars in web tmp dir locked on Win...

Posted by jbertram <gi...@git.apache.org>.
Github user jbertram commented on the issue:

    https://github.com/apache/activemq-artemis/pull/2473
  
    Wasn't there a Jetty issue opened about this? If so, how was that resolved?


---

[GitHub] activemq-artemis issue #2473: ARTEMIS-1058 Jars in web tmp dir locked on Win...

Posted by gaohoward <gi...@git.apache.org>.
Github user gaohoward commented on the issue:

    https://github.com/apache/activemq-artemis/pull/2473
  
    Yes there is a issue opened. https://github.com/eclipse/jetty.project/issues/1425
    that doesn't get fixed (PR didn't merged because the hacking into URLClassLoader brings concerns)
    So that's why i came up with this work around.
    (The issue still there with jetty latest releases).


---

[GitHub] activemq-artemis pull request #2473: ARTEMIS-1058 Jars in web tmp dir locked...

Posted by clebertsuconic <gi...@git.apache.org>.
Github user clebertsuconic commented on a diff in the pull request:

    https://github.com/apache/activemq-artemis/pull/2473#discussion_r243083234
  
    --- Diff: artemis-web/src/main/java/org/apache/activemq/artemis/component/WebServerComponent.java ---
    @@ -237,28 +236,39 @@ public void start() throws Exception {
        public void internalStop() throws Exception {
           server.stop();
           if (webContexts != null) {
    +
              File tmpdir = null;
    +         StringBuilder strBuilder = new StringBuilder();
    +         boolean found = false;
              for (WebAppContext context : webContexts) {
                 tmpdir = context.getTempDirectory();
     
    -            if (tmpdir != null && !context.isPersistTempDirectory()) {
    +            if (tmpdir != null && tmpdir.exists() && !context.isPersistTempDirectory()) {
                    //tmpdir will be removed by deleteOnExit()
    -               //somehow when broker is stopped and restarted quickly
    -               //this tmpdir won't get deleted sometimes
    -               boolean fileDeleted = TimeUtils.waitOnBoolean(false, 5000, tmpdir::exists);
    -
    -               if (!fileDeleted) {
    -                  //because the execution order of shutdown hooks are
    -                  //not determined, so it's possible that the deleteOnExit
    -                  //is executed after this hook, in that case we force a delete.
    -                  FileUtil.deleteDirectory(tmpdir);
    -                  logger.debug("Force to delete temporary file on shutdown: " + tmpdir.getAbsolutePath());
    -                  if (tmpdir.exists()) {
    -                     ActiveMQWebLogger.LOGGER.tmpFileNotDeleted(tmpdir);
    -                  }
    +               //However because the URLClassLoader never release/close its opened
    +               //jars the jar file won't be able to get deleted on Windows platform
    +               //until after the process fully terminated. To fix this here arranges
    +               //a separate process to try clean up the temp dir
    +               FileUtil.deleteDirectory(tmpdir);
    +               if (tmpdir.exists()) {
    +                  ActiveMQWebLogger.LOGGER.tmpFileNotDeleted(tmpdir);
    +                  strBuilder.append(tmpdir);
    +                  strBuilder.append(",");
    +                  found = true;
                    }
                 }
              }
    +
    +         if (found) {
    +            String artemisHome = System.getProperty("artemis.home");
    --- End diff --
    
    can't you get the property from other means? Fileconfiguration for instance?


---

[GitHub] activemq-artemis pull request #2473: ARTEMIS-1058 Jars in web tmp dir locked...

Posted by gaohoward <gi...@git.apache.org>.
Github user gaohoward commented on a diff in the pull request:

    https://github.com/apache/activemq-artemis/pull/2473#discussion_r243139995
  
    --- Diff: artemis-web/src/main/java/org/apache/activemq/artemis/component/WebServerComponent.java ---
    @@ -237,28 +236,39 @@ public void start() throws Exception {
        public void internalStop() throws Exception {
           server.stop();
           if (webContexts != null) {
    +
              File tmpdir = null;
    +         StringBuilder strBuilder = new StringBuilder();
    +         boolean found = false;
              for (WebAppContext context : webContexts) {
                 tmpdir = context.getTempDirectory();
     
    -            if (tmpdir != null && !context.isPersistTempDirectory()) {
    +            if (tmpdir != null && tmpdir.exists() && !context.isPersistTempDirectory()) {
                    //tmpdir will be removed by deleteOnExit()
    -               //somehow when broker is stopped and restarted quickly
    -               //this tmpdir won't get deleted sometimes
    -               boolean fileDeleted = TimeUtils.waitOnBoolean(false, 5000, tmpdir::exists);
    -
    -               if (!fileDeleted) {
    -                  //because the execution order of shutdown hooks are
    -                  //not determined, so it's possible that the deleteOnExit
    -                  //is executed after this hook, in that case we force a delete.
    -                  FileUtil.deleteDirectory(tmpdir);
    -                  logger.debug("Force to delete temporary file on shutdown: " + tmpdir.getAbsolutePath());
    -                  if (tmpdir.exists()) {
    -                     ActiveMQWebLogger.LOGGER.tmpFileNotDeleted(tmpdir);
    -                  }
    +               //However because the URLClassLoader never release/close its opened
    +               //jars the jar file won't be able to get deleted on Windows platform
    +               //until after the process fully terminated. To fix this here arranges
    +               //a separate process to try clean up the temp dir
    +               FileUtil.deleteDirectory(tmpdir);
    +               if (tmpdir.exists()) {
    +                  ActiveMQWebLogger.LOGGER.tmpFileNotDeleted(tmpdir);
    +                  strBuilder.append(tmpdir);
    +                  strBuilder.append(",");
    +                  found = true;
                    }
                 }
              }
    +
    +         if (found) {
    +            String artemisHome = System.getProperty("artemis.home");
    --- End diff --
    
    This "artemis.home" property is not defined in configured in broker.xml file. It's only defined in artemis.profile and set to system property in artemis.cmd script (-Dartemis.home="$ARTEMIS_HOME")
    I can't get it from the other configurations.



---