Uploaded image for project: 'JBoss Enterprise Application Platform'
  1. JBoss Enterprise Application Platform
  2. JBEAP-1507

Synchronization error in org.apache.activemq.artemis.core.server.NodeManager

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major Major
    • 7.0.0.ER2 (Beta)
    • 7.0.0.DR11
    • ActiveMQ
    • None

      In test NodeManagerTest#testLiveAnd2BackupsLiveForcesFailback exception occurs sometimes:

      org.apache.activemq.artemis.tests.integration.cluster.NodeManagerAction:Exception in thread "main" java.lang.IllegalStateException: Unable to create server lock file
      org.apache.activemq.artemis.tests.integration.cluster.NodeManagerAction:	at org.apache.activemq.artemis.core.server.NodeManager.setUpServerLockFile(NodeManager.java:182)
      org.apache.activemq.artemis.tests.integration.cluster.NodeManagerAction:	at org.apache.activemq.artemis.core.server.impl.FileLockNodeManager.start(FileLockNodeManager.java:70)
      org.apache.activemq.artemis.tests.integration.cluster.NodeManagerAction:	at org.apache.activemq.artemis.tests.integration.cluster.NodeManagerAction.main(NodeManagerAction.java:123)
      

      The problem is in setUpServerLockFile method of NodeManager class. To reproduce the issue, insert Thread.sleep into the setUpServerLockFile method.

      protected final synchronized void setUpServerLockFile() throws IOException {
            File serverLockFile = newFile(SERVER_LOCK_NAME);
      
            boolean fileCreated = false;
      
            int count = 0;
            while (!serverLockFile.exists()) {
               try {
                  Thread.sleep(5000);
               }
               catch (InterruptedException e) {
                  e.printStackTrace();
               }
               try {
                  fileCreated = serverLockFile.createNewFile();
               }
               catch (RuntimeException e) {
                  ActiveMQServerLogger.LOGGER.nodeManagerCantOpenFile(e, serverLockFile);
                  throw e;
               }
               catch (IOException e) {
                  /*
                  * on some OS's this may fail weirdly even tho the parent dir exists, retrying will work, some weird timing issue i think
                  * */
                  if (count < 5) {
                     try {
                        Thread.sleep(100);
                     }
                     catch (InterruptedException e1) {
                     }
                     count++;
                     continue;
                  }
                  ActiveMQServerLogger.LOGGER.nodeManagerCantOpenFile(e, serverLockFile);
                  throw e;
               }
               if (!fileCreated) {
                  throw new IllegalStateException("Unable to create server lock file");
               }
            }
      
            @SuppressWarnings("resource")
            RandomAccessFile raFile = new RandomAccessFile(serverLockFile, ACCESS_MODE);
      
            channel = raFile.getChannel();
      
            if (fileCreated) {
               ByteBuffer id = ByteBuffer.allocateDirect(3);
               byte[] bytes = new byte[3];
               bytes[0] = FIRST_TIME_START;
               bytes[1] = FIRST_TIME_START;
               bytes[2] = FIRST_TIME_START;
               id.put(bytes, 0, 3);
               id.position(0);
               channel.write(id, 0);
               channel.force(true);
            }
      
            createNodeId();
         }
      

            rh-ee-ataylor Andy Taylor
            eduda_jira Erich Duda (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: