2 Replies Latest reply on Dec 29, 2005 5:16 AM by Scott Stark

    Hacked solution for OutOfMemoryError on opening zip file on

    AndrewGoedhart Newbie

      I am writing this partly to help those who experience the problem at least have a way out and also to ask if there is another better way to solve this problem

      I am using release 4.03 SP1 and a 64 bit linux jvm with 4 GB memory and heap set at 2MB max. Sometimes on startup the jboss crashes with an OutOfMemoryError while trying to open a zip file. This can happen on a clean install and no apps loaded. When it happens the only solution is to restart the machine and hope. The first load normally works.

      In Jira the Jboss team says this is a jvm bug, It was supposed to be fixed in 403Sp1 but it seems that it isn't. The Jboss team seem to think that this is a jvm problem and not really their problem. Accoring to them Java should not run out of system memory opening an invalid jar or xml file. This problem really is a result of the jvm using memory mapped files for opening zip files, and this looks unlikely to change (its been discussed since jdk V1.3 on the bug tracking system). Unfortunately this make JBOSS unusable on a 64bit machine or where you need more then about 1.5 mB of memory. problem has been around since jdk1.3 and it looks like it won't change.

      I spent a very fustrating few weeks trying to find a solution for the problem and couldn't. I tried rejaring all the files in the lib directory, making sure I had enough heap space and system memory etc. Nothing worked

      Eventually I patched the RepositoryClassLoader.java file to ignore the EOutOfMemoryError. This works, the server loads now and does not crash. The services seem to be unaffected. Everything on our machines still run as per normal.

      My currently hacked solution is to download the source, patch the RepositoryClassLoader.java file with the patched method below and rebuild the jboss-jmx.jar and place the new jboss-jmx.jar file in the jboss/lib directory.

      If you would rather have the already patched jboss-jmx.jar please mail me on duosp.co.za (at) andrew.

      /---------------snip ------------------------/
       * Provides the same functionality as {@link java.net.URLClassLoader#getResource}.
       public URL getResourceLocally(String name)
       URL resURL = (URL) resourceCache.get(name);
       if (resURL != null)
       return resURL;
       if (isResourceBlackListed(name))
       return null;
       try {
       if( log.isTraceEnabled()){
       log.trace("getResourceLocally("+this+"), name="+name+", resURL:"+resURL);
       resURL = super.getResource(name);
       } catch( OutOfMemoryError e){
       resURL = null;
       log.error("OutOfMemoryError (sporadic error on AMD64 when opening zip files) for getResourceLocally("+this+"), name="+name+", resURL:"+resURL);
       if (resURL == null)
       resourceCache.put(name, resURL);
       return resURL;
      /-------------snip -------------------------------------/

      I still feel slightly uneasy about this hack, suffficiently so that i did not put it in the Jira. Unfortunately no one else seems to have any solution and I can't believe I am the only one who is getting this. It was happening on a virgin JBOSS install on some of our machines in the cluster.

      I hope this helps someone else with the same problem
      Any comments on how to solve the problem properly would be welcome.