Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-2416

inverted conditional maans that FileAllocator::run fails to trap failed open()s

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Trivial - P5 Trivial - P5
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • Environment:
      Found and fixed on Linux, but I believe the problem to be generic
    • ALL

      The code to allocate new data files reads as follows:

      try {
      log() << "allocating new datafile " << name << ", filling with zeroes..." << endl;
      long fd = open(name.c_str(), O_CREAT | O_RDWR | O_NOATIME, S_IRUSR | S_IWUSR);
      if ( fd <= 0 )

      { stringstream ss; ss << "couldn't open " << name << ' ' << errnoWithDescription(); massert( 10439 , ss.str(), fd <= 0 ); }

      The sense of the conditional on the massert() is inverted. The block is only
      entered for an invalid file descriptor, hence within it fd is always <= 0. As
      a result, the massert() never actually triggers, and so the error is neither
      logged nor trapped at this point.

      This isn't actually a big problem, as the invalid value in fd (typically -1)
      causes the system calls within ensureLength() to fail pretty soon after.
      (The posix_fallocate() fails and warns, and then the fallback code fails the
      first lseek(), logs and aborts).

      Patches attached for master, and for 1.6.6

      Nicholas Clark

        1. mongo-16.patch
          0.5 kB
        2. mongo-master.patch
          0.5 kB

            Assignee:
            Unassigned Unassigned
            Reporter:
            nicholas.clark Nicholas Clark
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: