Uploaded image for project: 'WiredTiger'
  1. WiredTiger
  2. WT-3824

tsc_nsec_ratio can compute to zero and cause divide by zero bug

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 3.6.3, 3.7.1, WT3.1.0
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None
    • Storage Engines
    • Storage 2018-01-15

      Following test suite in Evergreen has a few divide by zero errors:

      https://evergreen.mongodb.com/task/mongodb_mongo_master_ubuntu1604_debug_aubsan_lite_dbtest_WT_patch_e4405af1fa6d231a792cf62361968915a914fd2e_5a4d6cfe2fbabe782e0012d6_18_01_03_23_55_25

      For example, one instance of this error is as follows:

      https://logkeeper.mongodb.org/build/3399831e57c99a6b560be1dfa9e42982/test/5a4d7ee4be07c47ae78a33cb?raw=1

      I was able to reproduce this bug locally by adding the following assert:

      --- a/src/support/time.c
      +++ b/src/support/time.c
      @@ -7,6 +7,7 @@
        */
       
       #include "wt_internal.h"
      +#include <float.h>
       
       /*
        * __time_check_monotonic --
      @@ -89,6 +90,7 @@ __wt_tsc_to_nsec(WT_SESSION_IMPL *session, uint64_t end, uint64_t begin)
              if (end < begin)
                      return (0);
              tsc_diff = (double)(end - begin);
      +       WT_ASSERT(session, S2C(session)->tsc_nsec_ratio > DBL_EPSILON);
              return ((uint64_t)(tsc_diff / S2C(session)->tsc_nsec_ratio));
       }
      
      (gdb) bt
      #0  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:58
      #1  0x00007f01e16ee37a in __GI_abort () at abort.c:89
      #2  0x00007f01e1ddbd90 in __wt_abort (session=0x55d63caaacf8) at ../src/os_common/os_abort.c:31
      #3  0x00007f01e1e2c8e6 in __wt_assert (session=0x55d63caaacf8, error=0, file_name=0x7f01e1e7f950 <__func__.33150> "__wt_tsc_to_nsec", line_number=93, fmt=0x7f01e1e7f94b "%s") at ../src/support/err.c:501
      #4  0x00007f01e1e3e33d in __wt_tsc_to_nsec (session=0x55d63caaacf8, end=8169080459640816, begin=8169080459607018) at ../src/support/time.c:93
      #5  0x00007f01e1d3ba9a in __wt_write (session=0x55d63caaacf8, fh=0x55d63cac1a80, offset=0, len=21, buf=0x7f01e1e64790) at ../src/include/os_fhandle.i:198
      #6  0x00007f01e1d452d1 in __conn_single (session=0x55d63caaacf8, cfg=0x7ffc402cb670) at ../src/conn/conn_api.c:1776
      #7  0x00007f01e1d473a4 in wiredtiger_open (home=0x7ffc402cd0be "sec-db-copy/", event_handler=0x0, config=0x55d63caaac20 ",,log=(recover=error)", connectionp=0x7ffc402cb760) at ../src/conn/conn_api.c:2501
      #8  0x000055d63a8cd686 in main (argc=2, argv=0x7ffc402cb8d0) at ../src/utilities/util_main.c:278
      (gdb) f 4
      #4  0x00007f01e1e3e33d in __wt_tsc_to_nsec (session=0x55d63caaacf8, end=8169080459640816, begin=8169080459607018) at ../src/support/time.c:93
      (gdb) p ((WT_CONNECTION_IMPL *)(session)->iface.connection)->tsc_nsec_ratio
      $1 = 0
      

            Assignee:
            sue.loverso@mongodb.com Susan LoVerso
            Reporter:
            sulabh.mahajan@mongodb.com Sulabh Mahajan
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: