Skip to content

fix(liveness): release jweak ref when liveness table overflows or realloc fails#556

Merged
jbachorik merged 3 commits into
mainfrom
jb/liveTracker_fix
May 29, 2026
Merged

fix(liveness): release jweak ref when liveness table overflows or realloc fails#556
jbachorik merged 3 commits into
mainfrom
jb/liveTracker_fix

Conversation

@jbachorik
Copy link
Copy Markdown
Collaborator

@jbachorik jbachorik commented May 28, 2026

What does this PR do?:

Fixes three jweak reference leaks in LivenessTracker::track() when the tracking table cannot accept a new entry.

Motivation:

Some leftovers with potential of memory leaks in critical conditions.

Additional Notes:

Three paths in livenessTracker.cpp dropped the JNI weak global ref without calling DeleteWeakGlobalRef:

  1. realloc failure: when resizing failed, the code fell through to goto retry so cleanup_table's freed slots could still be used. If the retry also failed (retried==true, idx==_table_cap), the ref was silently dropped. Fixed by adding an else { DeleteWeakGlobalRef(ref); } on the retried==true path that handles final-failure cleanup.

  2. Table at max capacity (initial pass): the ref was silently dropped when _table_cap == _table_max_cap. Now deleted before exiting.

  3. Table still full after resize retry (retried==true): concurrent threads can re-fill all newly-allocated slots before the retrying thread wins the CAS. This path had no cleanup. Fixed by the same else { DeleteWeakGlobalRef(ref); } added for case 1.

How to test the change?:

Code inspection — the three affected paths are straightforward error exits that previously had no DeleteWeakGlobalRef call.

  • If this PR touches code that signs or publishes builds or packages, or handles
    credentials of any kind, I've requested a review from @DataDog/security-design-and-guidance.
  • This PR doesn't touch any of that.
  • JIRA: PROF-14823

…lloc fails

PROF-14823

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@jbachorik jbachorik added the AI label May 28, 2026
@dd-octo-sts
Copy link
Copy Markdown
Contributor

dd-octo-sts Bot commented May 28, 2026

CI Test Results

Run: #26620665645 | Commit: e9cb207 | Duration: 12m 55s (longest job)

All 32 test jobs passed

Status Overview

JDK glibc-aarch64/debug glibc-amd64/debug musl-aarch64/debug musl-amd64/debug
8 - - -
8-ibm - - -
8-j9 - -
8-librca - -
8-orcl - - -
11 - - -
11-j9 - -
11-librca - -
17 - -
17-graal - -
17-j9 - -
17-librca - -
21 - -
21-graal - -
21-librca - -
25 - -
25-graal - -
25-librca - -

Legend: ✅ passed | ❌ failed | ⚪ skipped | 🚫 cancelled

Summary: Total: 32 | Passed: 32 | Failed: 0


Updated: 2026-05-29 06:30:58 UTC

@datadog-datadog-prod-us1
Copy link
Copy Markdown
Contributor

datadog-datadog-prod-us1 Bot commented May 28, 2026

Pipelines

Fix all issues with BitsAI

⚠️ Warnings

🚦 2 Pipeline jobs failed

CI Run | test-matrix / test-linux-glibc-amd64 (11, debug)   View in Datadog   GitHub Actions

🔄 Retry job. This looks flaky and may succeed on retry. Connection issues while trying to resolve address results-receiver.actions.githubusercontent.com: getaddrinfo EAI_AGAIN.

CI Run | check-javadoc   View in Datadog   GitHub Actions

🛟 This job is unlikely to succeed on retry. Please review your pipeline configuration. Java setup process failed with error code: 520.

Useful? React with 👍 / 👎

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 4b43ca2 | Docs | Datadog PR Page | Give us feedback!

…alloc failure

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@jbachorik jbachorik marked this pull request as ready for review May 28, 2026 22:03
@jbachorik jbachorik requested a review from a team as a code owner May 28, 2026 22:03
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: be3fe3bb21

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread ddprof-lib/src/main/cpp/livenessTracker.cpp Outdated
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes jweak leaks in LivenessTracker::track() when an allocation can’t be added to the liveness tracking table, ensuring weak refs are properly released on failure/overflow paths.

Changes:

  • Call DeleteWeakGlobalRef when the tracking table is at max capacity and cannot accept the new entry.
  • Call DeleteWeakGlobalRef on the post-retry overflow path (e.g., after a failed resize attempt / still full after cleanup), preventing a dropped jweak from leaking.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread ddprof-lib/src/main/cpp/livenessTracker.cpp
@jbachorik jbachorik merged commit b3f7d38 into main May 29, 2026
338 of 343 checks passed
@jbachorik jbachorik deleted the jb/liveTracker_fix branch May 29, 2026 06:19
@github-actions github-actions Bot added this to the 1.44.0 milestone May 29, 2026
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.

2 participants