Skip to content

rgw: fix memory leak in RGWHTTPManager thread cleanup#66874

Merged
ivancich merged 1 commit intoceph:mainfrom
tchaikov:wip-rgw-client-fix-leak
Feb 5, 2026
Merged

rgw: fix memory leak in RGWHTTPManager thread cleanup#66874
ivancich merged 1 commit intoceph:mainfrom
tchaikov:wip-rgw-client-fix-leak

Conversation

@tchaikov
Copy link
Contributor

@tchaikov tchaikov commented Jan 9, 2026

Fix memory leak detected by AddressSanitizer in unittest_http_manager. The test was failing with ASan enabled due to rgw_http_req_data objects not being properly cleaned up when the HTTP manager thread exits.

ASan reported the following leaks:

  Direct leak of 17152 byte(s) in 32 object(s) allocated from:
    #0 operator new(unsigned long)
    #1 RGWHTTPManager::add_request(RGWHTTPClient*)
       /ceph/src/rgw/rgw_http_client.cc:946:33
    #2 HTTPManager_SignalThread_Test::TestBody()
       /ceph/src/test/rgw/test_http_manager.cc:132:10
  Indirect leak of 768 byte(s) in 32 object(s) allocated from:
    #0 operator new(unsigned long)
    #1 rgw_http_req_data::rgw_http_req_data()
       /ceph/src/rgw/rgw_http_client.cc:52:22
    #2 RGWHTTPManager::add_request(RGWHTTPClient*)
       /ceph/src/rgw/rgw_http_client.cc:946:37
  SUMMARY: AddressSanitizer: 17920 byte(s) leaked in 64 allocation(s).

Root cause: The rgw_http_req_data class uses reference counting (inherits from RefCountedObject). When a request is unregistered, unregister_request() calls get() to increment the refcount, expecting a corresponding put() to be called later.

In manage_pending_requests(), unregistered requests are properly handled with both _unlink_request() and put(). However, in the thread cleanup code (reqs_thread_entry exit path), only _unlink_request() was called without the matching put(), causing a reference count leak.

The fix adds the missing put() call in the thread cleanup code to match the reference counting pattern used in manage_pending_requests().

Test results:

  • Before: 17,920 bytes leaked in 64 allocations
  • After: 0 leaks, unittest_http_manager passes with ASan

Fixes: https://tracker.ceph.com/issues/74762

Contribution Guidelines

  • To sign and title your commits, please refer to Submitting Patches to Ceph.

  • If you are submitting a fix for a stable branch (e.g. "quincy"), please refer to Submitting Patches to Ceph - Backports for the proper workflow.

  • When filling out the below checklist, you may click boxes directly in the GitHub web UI. When entering or editing the entire PR message in the GitHub web UI editor, you may also select a checklist item by adding an x between the brackets: [x]. Spaces and capitalization matter when checking off items this way.

Checklist

  • Tracker (select at least one)
    • References tracker ticket
    • Very recent bug; references commit where it was introduced
    • New feature (ticket optional)
    • Doc update (no ticket needed)
    • Code cleanup (no ticket needed)
  • Component impact
    • Affects Dashboard, opened tracker ticket
    • Affects Orchestrator, opened tracker ticket
    • No impact that needs to be tracked
  • Documentation (select at least one)
    • Updates relevant documentation
    • No doc update is appropriate
  • Tests (select at least one)
Show available Jenkins commands

You must only issue one Jenkins command per-comment. Jenkins does not understand
comments with more than one command.

@tchaikov tchaikov requested a review from a team as a code owner January 9, 2026 23:55
@github-actions github-actions bot added the rgw label Jan 9, 2026
@tchaikov tchaikov mentioned this pull request Jan 10, 2026
14 tasks
@ivancich ivancich added the wip-eric-testing-1 for ivancich testing label Jan 29, 2026
@ivancich
Copy link
Member

ivancich commented Feb 3, 2026

Teuthology results (no regressions):

@ivancich
Copy link
Member

ivancich commented Feb 3, 2026

@tchaikov This seems like this might be worthy of backports, but there's no linked tracker. So it's ready to merge, but I'll let you figure out the tracker situation first. Thanks. cc: @cbodley

Fix memory leak detected by AddressSanitizer in unittest_http_manager.
The test was failing with ASan enabled due to rgw_http_req_data objects
not being properly cleaned up when the HTTP manager thread exits.

ASan reported the following leaks:

  Direct leak of 17152 byte(s) in 32 object(s) allocated from:
    #0 operator new(unsigned long)
    #1 RGWHTTPManager::add_request(RGWHTTPClient*)
       /ceph/src/rgw/rgw_http_client.cc:946:33
    #2 HTTPManager_SignalThread_Test::TestBody()
       /ceph/src/test/rgw/test_http_manager.cc:132:10

  Indirect leak of 768 byte(s) in 32 object(s) allocated from:
    #0 operator new(unsigned long)
    #1 rgw_http_req_data::rgw_http_req_data()
       /ceph/src/rgw/rgw_http_client.cc:52:22
    #2 RGWHTTPManager::add_request(RGWHTTPClient*)
       /ceph/src/rgw/rgw_http_client.cc:946:37

  SUMMARY: AddressSanitizer: 17920 byte(s) leaked in 64 allocation(s).

Root cause: The rgw_http_req_data class uses reference counting
(inherits from RefCountedObject). When a request is unregistered,
unregister_request() calls get() to increment the refcount, expecting
a corresponding put() to be called later.

In manage_pending_requests(), unregistered requests are properly
handled with both _unlink_request() and put(). However, in the thread
cleanup code (reqs_thread_entry exit path), only _unlink_request() was
called without the matching put(), causing a reference count leak.

The fix adds the missing put() call in the thread cleanup code to match
the reference counting pattern used in manage_pending_requests().

Test results:
- Before: 17,920 bytes leaked in 64 allocations
- After: 0 leaks, unittest_http_manager passes with ASan

Fixes: https://tracker.ceph.com/issues/74762
Signed-off-by: Kefu Chai <k.chai@proxmox.com>
@tchaikov tchaikov force-pushed the wip-rgw-client-fix-leak branch from 3973a52 to 6faba4c Compare February 5, 2026 03:46
@tchaikov
Copy link
Contributor Author

tchaikov commented Feb 5, 2026

@tchaikov This seems like this might be worthy of backports, but there's no linked tracker. So it's ready to merge, but I'll let you figure out the tracker situation first. Thanks. cc: @cbodley

@ivancich hi Eric, thank you for the reminder. i just created a tracker ticket and linked this pull request with it.

@ivancich ivancich merged commit 55b447b into ceph:main Feb 5, 2026
15 of 16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants