Uploaded image for project: 'Solr'
  1. Solr
  2. SOLR-11782

LatchWatcher.await doesn’t protect against spurious wakeup

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 7.3, 8.0
    • Component/s: None
    • Labels:
      None

      Description

      I noticed that LatchWatcher.await does:

      public void await(long timeout) throws InterruptedException {
            synchronized (lock) {
              if (this.event != null) return;
              lock.wait(timeout);
            }
          }
      

      while the recommendation of lock.wait is to check the wait condition even after the method returns in case of spurious wakeup. lock is a private local field to which notifyAll is called only after a zk event is being handled. I think we should check the await method to something like:

      public void await(long timeout) throws InterruptedException {
            assert timeout > 0;
            long timeoutTime = System.currentTimeMillis() + timeout;
            synchronized (lock) {
              while (this.event == null) {
                long nextTimeout = timeoutTime - System.currentTimeMillis();
                if (nextTimeout <= 0) {
                  return;
                }
                lock.wait(nextTimeout);
              }
            }
          }
      

        Attachments

        1. SOLR-11782.patch
          8 kB
          Tomás Fernández Löbbe
        2. SOLR-11782.patch
          7 kB
          Tomás Fernández Löbbe
        3. SOLR-11782.patch
          0.9 kB
          Tomás Fernández Löbbe

          Activity

            People

            • Assignee:
              tomasflobbe Tomás Fernández Löbbe
              Reporter:
              tomasflobbe Tomás Fernández Löbbe
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: