Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8199210

Condition.await blocks forever even after calling Condition.signalAll and the condition lock is free

    Details

      Description

      FULL PRODUCT VERSION :
      Tested with two JDKs:

      1. openjdk version "1.8.0_151"
      OpenJDK Runtime Environment (build 1.8.0_151-8u151-b12-0ubuntu0.16.04.2-b12)
      OpenJDK 64-Bit Server VM (build 25.151-b12, mixed mode)

      2. Oracle JDK: jdk-8u162-linux-x64.tar.gz


      ADDITIONAL OS VERSION INFORMATION :
      RELEASE=18
      CODENAME=sarah
      EDITION="Cinnamon 64-bit"
      DESCRIPTION="Linux Mint 18 Sarah"


      EXTRA RELEVANT SYSTEM CONFIGURATION :
      cat /proc/cpuinfo
      processor : 0
      vendor_id : GenuineIntel
      cpu family : 6
      model : 60
      model name : Intel(R) Core(TM) i7-4712HQ CPU @ 2.30GHz
      stepping : 3
      microcode : 0x17
      cpu MHz : 2141.785
      cache size : 6144 KB
      physical id : 0
      siblings : 8
      core id : 0
      cpu cores : 4
      apicid : 0
      initial apicid : 0
      fpu : yes
      fpu_exception : yes
      cpuid level : 13
      wp : yes
      flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf eagerfpu pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm epb tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid xsaveopt dtherm ida arat pln pts
      bugs :
      bogomips : 4589.19
      clflush size : 64
      cache_alignment : 64
      address sizes : 39 bits physical, 48 bits virtual
      power management:

      processor : 1
      vendor_id : GenuineIntel
      cpu family : 6
      model : 60
      model name : Intel(R) Core(TM) i7-4712HQ CPU @ 2.30GHz
      stepping : 3
      microcode : 0x17
      cpu MHz : 1844.671
      cache size : 6144 KB
      physical id : 0
      siblings : 8
      core id : 1
      cpu cores : 4
      apicid : 2
      initial apicid : 2
      fpu : yes
      fpu_exception : yes
      cpuid level : 13
      wp : yes
      flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf eagerfpu pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm epb tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid xsaveopt dtherm ida arat pln pts
      bugs :
      bogomips : 4589.19
      clflush size : 64
      cache_alignment : 64
      address sizes : 39 bits physical, 48 bits virtual
      power management:

      processor : 2
      vendor_id : GenuineIntel
      cpu family : 6
      model : 60
      model name : Intel(R) Core(TM) i7-4712HQ CPU @ 2.30GHz
      stepping : 3
      microcode : 0x17
      cpu MHz : 2294.699
      cache size : 6144 KB
      physical id : 0
      siblings : 8
      core id : 2
      cpu cores : 4
      apicid : 4
      initial apicid : 4
      fpu : yes
      fpu_exception : yes
      cpuid level : 13
      wp : yes
      flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf eagerfpu pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm epb tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid xsaveopt dtherm ida arat pln pts
      bugs :
      bogomips : 4589.19
      clflush size : 64
      cache_alignment : 64
      address sizes : 39 bits physical, 48 bits virtual
      power management:

      processor : 3
      vendor_id : GenuineIntel
      cpu family : 6
      model : 60
      model name : Intel(R) Core(TM) i7-4712HQ CPU @ 2.30GHz
      stepping : 3
      microcode : 0x17
      cpu MHz : 2314.824
      cache size : 6144 KB
      physical id : 0
      siblings : 8
      core id : 3
      cpu cores : 4
      apicid : 6
      initial apicid : 6
      fpu : yes
      fpu_exception : yes
      cpuid level : 13
      wp : yes
      flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf eagerfpu pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm epb tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid xsaveopt dtherm ida arat pln pts
      bugs :
      bogomips : 4589.19
      clflush size : 64
      cache_alignment : 64
      address sizes : 39 bits physical, 48 bits virtual
      power management:

      processor : 4
      vendor_id : GenuineIntel
      cpu family : 6
      model : 60
      model name : Intel(R) Core(TM) i7-4712HQ CPU @ 2.30GHz
      stepping : 3
      microcode : 0x17
      cpu MHz : 2522.812
      cache size : 6144 KB
      physical id : 0
      siblings : 8
      core id : 0
      cpu cores : 4
      apicid : 1
      initial apicid : 1
      fpu : yes
      fpu_exception : yes
      cpuid level : 13
      wp : yes
      flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf eagerfpu pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm epb tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid xsaveopt dtherm ida arat pln pts
      bugs :
      bogomips : 4589.19
      clflush size : 64
      cache_alignment : 64
      address sizes : 39 bits physical, 48 bits virtual
      power management:

      processor : 5
      vendor_id : GenuineIntel
      cpu family : 6
      model : 60
      model name : Intel(R) Core(TM) i7-4712HQ CPU @ 2.30GHz
      stepping : 3
      microcode : 0x17
      cpu MHz : 2352.468
      cache size : 6144 KB
      physical id : 0
      siblings : 8
      core id : 1
      cpu cores : 4
      apicid : 3
      initial apicid : 3
      fpu : yes
      fpu_exception : yes
      cpuid level : 13
      wp : yes
      flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf eagerfpu pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm epb tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid xsaveopt dtherm ida arat pln pts
      bugs :
      bogomips : 4589.19
      clflush size : 64
      cache_alignment : 64
      address sizes : 39 bits physical, 48 bits virtual
      power management:

      processor : 6
      vendor_id : GenuineIntel
      cpu family : 6
      model : 60
      model name : Intel(R) Core(TM) i7-4712HQ CPU @ 2.30GHz
      stepping : 3
      microcode : 0x17
      cpu MHz : 2721.277
      cache size : 6144 KB
      physical id : 0
      siblings : 8
      core id : 2
      cpu cores : 4
      apicid : 5
      initial apicid : 5
      fpu : yes
      fpu_exception : yes
      cpuid level : 13
      wp : yes
      flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf eagerfpu pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm epb tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid xsaveopt dtherm ida arat pln pts
      bugs :
      bogomips : 4589.19
      clflush size : 64
      cache_alignment : 64
      address sizes : 39 bits physical, 48 bits virtual
      power management:

      processor : 7
      vendor_id : GenuineIntel
      cpu family : 6
      model : 60
      model name : Intel(R) Core(TM) i7-4712HQ CPU @ 2.30GHz
      stepping : 3
      microcode : 0x17
      cpu MHz : 2755.058
      cache size : 6144 KB
      physical id : 0
      siblings : 8
      core id : 3
      cpu cores : 4
      apicid : 7
      initial apicid : 7
      fpu : yes
      fpu_exception : yes
      cpuid level : 13
      wp : yes
      flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf eagerfpu pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm epb tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid xsaveopt dtherm ida arat pln pts
      bugs :
      bogomips : 4589.19
      clflush size : 64
      cache_alignment : 64
      address sizes : 39 bits physical, 48 bits virtual
      power management:


      A DESCRIPTION OF THE PROBLEM :
      Within a specific program, I am calling creating a lock and a condition:

          private final Lock mLock = new ReentrantLock();
          private final Condition mCondition = mLock.newCondition();
          private volatile boolean mSignalled = false;

      Then one piece of code is blocking on the condition (consumer thread):

          while (!isDone()) {
           mLock.lock();
                  try {
                      mCondition.await();
                  } catch (InterruptedException e) {
                      throw e;
                  } finally {
                   mLock.unlock();
                  }
          }

      And another part (producer thread) is definitely signalling the condition (see below), but the consumer thread is never woken up:

          private void onComplete() {
              mLock.lock();
              try {
                  mCondition.signalAll();
                  mSignalled = true;
              } finally {
                  mLock.unlock();
              }
          }

      The condition lock is definitely not locked anymore, but it is free.
      When breaking in the Eclipse debugger, I see that the condition has been signalled (mSignalled), that the condition lock is free and that the consumer really is done (isDone would return true).
      But the consumer thread is still stuck in Condition.wait and condition waitStatus is -2.
      Also if I do not await forever, but let's say await for 10s everything is proceeding after 10s (since all requirements to proceed are met.)

      Rewriting the code using synchronized, wait and notifyAll works fine and does not show the error.

      The error is reproducable (about 33%) in a specific version of my workspace.
      If I just do some refactorings somewhere else, everything works fine.
      I assume this might be a timing / memory barrier issue in Unsafe.park.

      The issue is happening within this class: https://github.com/Himmele/Mindroid.java/blob/master/src/mindroid/util/concurrent/Promise.java

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      See description.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      See description.
      ACTUAL -
      See description.

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      None, waiting thread just blocks forever.

      REPRODUCIBILITY :
      This bug can be reproduced often.

      ---------- BEGIN SOURCE ----------
      I can provide a set of source/class files to reproduce the error if you want to.
      I can also provide a screenshot showing the state of the program, condition variable and condition lock if it helps.
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Switching form the ReentrantLock, Condition API to synchronized, wait and notify:

      Consumer:
                  synchronized (this) {
                   try {
                   wait();
                      } catch (InterruptedException e) {
                          throw e;
                      }
                  }

      Producer:
              synchronized (this) {
               notifyAll();
               mSignalled = true;
              }

        Attachments

          Activity

            People

            • Assignee:
              psonal Pallavi Sonal
              Reporter:
              webbuggrp Webbug Group
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: