Uploaded image for project: 'ActiveMQ Classic'
  1. ActiveMQ Classic
  2. AMQ-3673

Unexpected behavior in FailoverTransport when hosts are unknown

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • 5.5.0
    • 5.6.0
    • JMS client
    • None
    • MacOS X 10.5
      Java(TM) SE Runtime Environment (build 1.6.0_26-b03-384-10M3425)

    • Patch Available

    Description

      There's an unexpected behavior when a failover url is specified where the first host does not exist, e.g.

      failover:(tcp://nonexistinghost.mydomain.com:61616,tcp://existinghost.mydomain.com:61616)?randomize=false

      The failover code will never switch to the tcp://existinghost.mydomain.com:61616 while when using this url:

      failover:(tcp://nonexistinghost.mydomain.com:61617,tcp://existinghost.mydomain.com:61616)?randomize=false

      The failover works flawlessly. I tracket the problem down to the method org.apache.activemq.transport.failover.FailoverTransport.contains(URI):

      private boolean contains(URI newURI) {
      
              boolean result = false;
              try {
              for (URI uri:uris) {
                  if (newURI.getPort()==uri.getPort()) {
                      InetAddress newAddr = InetAddress.getByName(newURI.getHost());
                      InetAddress addr = InetAddress.getByName(uri.getHost());
                      if (addr.equals(newAddr)) {
                          result = true;
                          break;
                      }
                  }
              }
              }catch(IOException e) {
                  result = true;
                  LOG.error("Failed to verify URI " + newURI + " already known: " + e);
              }
              return result;
          }
      
      

      That only resolves hostnames if the ports are not equal (this is why the different port behavior comes from).

      In above mentioned case in the second call to this method this line fails with a UnknownHostException:

      InetAddress addr = InetAddress.getByName(uri.getHost());
      

      and the result of contains() is set to true because of the catch block, therefore the second URL isn't added to the list of urls.

      I suggest to change the catch block to return false. In case of an IOException during the check it's hard to say whether the URIs are the same or not, but it's more likely that they're not the same as in this case.

      Attachments

        1. patch.diff
          0.3 kB
          Stefan Riesen
        2. FailoverNoHostException.java
          1 kB
          Stefan Riesen

        Activity

          People

            tabish Timothy A. Bish
            notiriel Stefan Riesen
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: