Uploaded image for project: 'Hadoop HDFS'
  1. Hadoop HDFS
  2. HDFS-8707 Implement an async pure c++ HDFS client
  3. HDFS-9265

InputStreamImpl should hold a shared_ptr of the BlockReader

    XMLWordPrintableJSON

Details

    • Sub-task
    • Status: Resolved
    • Blocker
    • Resolution: Fixed
    • None
    • HDFS-8707
    • hdfs-client
    • None
    • Reviewed

    Description

      The remote block reader relies on undefined behavior in how it uses enable_shared_from_this.

      http://en.cppreference.com/w/cpp/memory/enable_shared_from_this

      The spec states a shared_ptr to an object inheriting from enable_shared_from_this must be live before calling make_shared_from_this.
      Calling make_shared_from_this without an existing shared_ptr is undefined behavior and causes deterministic crashes when the code is built with GCC.

      example:
      class foo : public enable_shared_from_this

      {/*bar*/}

      ;

      safe:
      auto ptr1 = std::make_shared<foo>();
      auto ptr2 = foo->make_shared_from_this();

      broken:
      foo *ptr = new foo();
      auto ptr2 = foo->make_shared_from_this(); //no existing live shared_ptr

      In order to fix the input stream should call std::make_shared and hang onto a shared_ptr to the block reader. The block reader will then be free to call make_shared_from this as much as it wants without issue.

      Attachments

        1. HDFS-9265.HDFS-8707.000.patch
          1 kB
          James Clampffer

        Activity

          People

            James Clampffer James Clampffer
            James Clampffer James Clampffer
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: