ICEfaces
  1. ICEfaces
  2. ICE-4717

Simplify thread blocking code

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.8.1
    • Fix Version/s: 1.8.2-RC1, 1.8.2
    • Component/s: Framework
    • Labels:
      None
    • Environment:
      server

      Description

      Through studying the semaphore logic of the Thread Blocking environment a race condition was discovered causing another thread leak. Due to time-slicing it could happen that the Servlet Container supplied thread decides to use the semaphore logic to block and another thread trying to send a response decides the semaphore logic is not in effect yet and will not release the semaphore eventually. This causes the Servlet Container supplied thread to block and never gets unblocked.

          public void respondWith(final ResponseHandler handler) throws Exception {
              try {
                  super.respondWith(handler);
              } finally {
                  if (semaphore == null) {
      --> timeslicing
                      blockResponse = false;
                  } else {
                      semaphore.release();
                  }
              }
          }

          public void blockUntilRespond() throws InterruptedException {
              if (blockResponse) {
      --> timeslicing
                  semaphore = new Semaphore(1);
                  semaphore.acquire();
                  boolean acquired = semaphore.tryAcquire(TIMEOUT, TimeUnit.MINUTES);
                  if (acquired) {
                      semaphore.release();
                  } else {
                      // log some warning
                      semaphore.release();
                  }
              }
          }

      The thread blocking code (ThreadBlockingAdaptingServlet) should use immutable objects to avoid any synchronization issues.

        Activity

        Hide
        Mircea Toma added a comment -

        Simplify interaction with semaphore. Make ThreadBlockingRequestResponse immutable.

        Show
        Mircea Toma added a comment - Simplify interaction with semaphore. Make ThreadBlockingRequestResponse immutable.

          People

          • Assignee:
            Mircea Toma
            Reporter:
            Mircea Toma
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: