Uploaded image for project: 'Undertow'
  1. Undertow
  2. UNDERTOW-1701

GracefulShutdownHandler has race condition that results in shutdownComplete not called

    Details

      Description

      UNDERTOW-1099 fix introduced a different bug which results in listeners not being called.

          private void decrementRequests() {
              if (shutdown) {
                  //we don't read the request count until after checking the shutdown variable
                  //otherwise we could read the request count as zero, a new request could state, and then we shutdown
                  //see https://issues.jboss.org/browse/UNDERTOW-1099
                  long active = activeRequestsUpdater.decrementAndGet(this);
                  synchronized (lock) {
                      if (active == 0) {
                          shutdownComplete();
                      }
                  }
              } else {
                  activeRequestsUpdater.decrementAndGet(this);
              }
          }
      

      Thread T1 calls decrementRequests. Shutdown is false, so this thread will follow the 'else' path in preparation for decrementAndGet
      Thread T2 calls shutdown. Increments from 1 to 2, sets shutdown=true, and calls decrementRequests where decrementAndGet results in 1
      Thread T1 completes the decrementRequests invocation reducing the active request count to zero in the else path without calling shutdownComplete.

      Flavia Rainone I don't have permissions to reopen this, would you prefer that I open a new ticket?

      I would propose using a bit mask to represent both shutdownRequested and shutdownComplete to allow state changes within individual cas operations.

        Gliffy Diagrams

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  ckozak Carter Kozak
                  Reporter:
                  flavia.rainone Flavia Rainone
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  2 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved: