Uploaded image for project: 'Blazegraph (by SYSTAP)'
  1. Blazegraph (by SYSTAP)
  2. BLZG-768

Bad patterns for timeout computations

    XMLWordPrintable

    Details

      Description

      There are several places in the code where we decrement a nanosecond field until a timeout is exceeded or a condition is satisfied. Some of these code snips are wrong, causing timeouts to terminate too soon.

      The correct pattern is:

                  long remaining = nanos - (System.nanoTime() - begin);
      

      where [nanos] is the timeout expressed in nanoseconds.

      The following pattern is NOT correct since it decrements by the
      total elapsed time in each iteration and will cause the timeout to
      expire too soon.

                  nanos -= (System.nanoTime() - begin);
      

      The ConcurrencyManager, WriteExecutorService and BlockingBuffer use
      a different pattern which is also correct. This pattern computes
      the elapsed since the last timestamp rather than the elapsed since
      the start of the timeout pattern.

                          final long now = System.nanoTime();
                          
                          nanos -= now - lastTime;
      

        Attachments

          Activity

            People

            Assignee:
            bryanthompson bryanthompson
            Reporter:
            bryanthompson bryanthompson
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: