Uploaded image for project: 'JGroups'
  1. JGroups
  2. JGRP-536

Catching InterruptedException and setting interrupt bit in a loop might cause infinite loop

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • Major
    • 2.5
    • None
    • None

    Description

      FC.handleDownMessage() has the following code:
      while(length > lowest_credit && running) {
      try {
      boolean rc=credits_available.await(max_block_time, TimeUnit.MILLISECONDS);
      if(rc || length <= lowest_credit || !running)
      break;

      long wait_time=System.currentTimeMillis() - last_credit_request;
      if(wait_time >= max_block_time) {

      // we have to set this var now, because we release the lock below (for sending a
      // credit request), so all blocked threads would send a credit request, leading to
      // a credit request storm
      last_credit_request=System.currentTimeMillis();

      // we need to send the credit requests down without holding the sent_lock, otherwise we might
      // run into the deadlock described in http://jira.jboss.com/jira/browse/JGRP-292
      Map<Address,Long> sent_copy=new HashMap<Address,Long>(sent);
      sent_copy.keySet().retainAll(creditors);
      sent_lock.unlock();
      try {
      // System.out.println(new Date() + " --> credit request");
      for(Map.Entry<Address,Long> entry: sent_copy.entrySet())

      { sendCreditRequest(entry.getKey(), entry.getValue()); }

      }
      finally

      { sent_lock.lock(); }

      }
      }
      catch(InterruptedException e)

      { // set the interrupted flag again, so the caller's thread can handle the interrupt as well Thread.currentThread().interrupt(); }

      }

      So if the thread is interrupted, unless

      length < lowest_credit || !running,

      we will have an infinite loop !

      SOLUTION: we cannot set the interrupt flag again, because we don't return from the loop !

      Attachments

        Activity

          People

            rhn-engineering-bban Bela Ban
            rhn-engineering-bban Bela Ban
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: