ExportXMLWordPrintableJSON

    • Type: Bug
    • Resolution: Unresolved
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Cursors
    • None
    • Environment:
      GCC 13, Ubuntu 24.04
    • Storage Engines - Foundations
    • 759.028
    • None
    • 1

      __wt_session_reset_cursors (session_api.c line 28) frees cached cursor key and value buffers when called with free_buffers=true (as in WT_SESSION::reset, line 1301). The loop contains an early exit if (session->ncursors == 0) break; (line 35) intended as a fast-path for callers that only need to unposition cursors. However, session->ncursors tracks the count of positioned cursors, not the total number of open cursors in session->cursors. When WT_SESSION::reset() is called with cursors already unpositioned (the common case in session pool patterns), session->ncursors is already 0 at the first loop iteration, causing an immediate break that bypasses all __wt_buf_free calls. The cached key and value memory (allocated by prior search, insert, or set_key/set_value calls) is never released, violating the API contract that WT_SESSION::reset "discards cached resources." 

      For Reproduce:
      I added catch2 unit test (test_session_reset_cursors.cpp) reproduces the bug and verifies the fix. (I added before/after outputs on JIRA).
      In a scenario where a cursor holds allocated key/value heap buffers but is unpositioned (session->ncursors == 0), calling session->reset() leaves cursor->key.mem and cursor - >value.mem non-NULL without the fix, causing CHECK(cursor->key.mem == nullptr) to fail. 
      With the fix, __wt_session_reset_cursors does not break early when free_buffers=true and correctly frees all open cursor buffers.

      Proposed Fix:
      Change the early break condition in __wt_session_reset_cursors (session_api.c line 35) from if (session->ncursors == 0) to if (!free_buffers && session->ncursors == 0), preserving the fast-path optimization for all callers that pass free_buffers=false while ensuring WT_SESSION::reset correctly traverses and frees buffers for all open cursors.

        1. after_fix_output.txt
          0.2 kB
        2. before_fix_output.txt
          1 kB

            Assignee:
            [DO NOT USE] Backlog - Storage Engines Team
            Reporter:
            Tuna KARABACAK (EXT)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: