Skip to content

fix(sidecar): remove spurious deletion of runtimes on set_session_config - #2277

Merged
gh-worker-dd-mergequeue-cf854d[bot] merged 1 commit into
mainfrom
glopes/sidecar-runtime-lease
Jul 27, 2026
Merged

fix(sidecar): remove spurious deletion of runtimes on set_session_config#2277
gh-worker-dd-mergequeue-cf854d[bot] merged 1 commit into
mainfrom
glopes/sidecar-runtime-lease

Conversation

@cataphract

@cataphract cataphract commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

EDIT: After discussion, pending deeper refactoring, fix just the spurious runtime deletion on set_session_config.

What does this PR do?

  1. Ownership correction: replace the per-connection HashSet<InstanceId> with counted RuntimeLeases.
  2. Reconfiguration semantics: stop treating set_session_config() aas a reason to destroy all existing runtimes (when is_fork=false).

First, this replaces runtime teardown based on per-connection recorded IDs and explicit shutdown RPCs with lease-based shared ownership. Each connection holds at most one RuntimeLease per InstanceId. Acquiring the first lease creates a RuntimeEntry with one owner; subsequent acquisitions increment its semantic owner count. Dropping a lease decrements that count, and dropping the final lease removes and shuts down the runtime. Non-owning runtime lookups are available where needed (peek_runtime).

Before, when a connection closed, it would calls shutdown_runtime() for every recorded id. Consequently, if two connections use the same runtime, the first one to disconnect can remove it even while the second connection remains alive.

Secondly, set_session_config called session.shutdown_running_instances() for every non-fork connection, which drained all runtimes of the session. An enqueue_actions that was concurrently in flight then re-created an empty RuntimeInfo, logged "No application found" and dropped the telemetry payload. So we cannot allow session reconfiguration to bypass the lease ownership model.

Notes:

Because reclamation now happens in Drop, RuntimeInfo::shutdown and SessionInfo::shutdown must stay synchronous; they are, since neither awaits.

With ownership tracked by leases, the shutdown_runtime and shutdown_session RPCs and the is_fork argument of set_session_config become redundant, so they are removed from the wire interface.

Motivation

We're seeing flaky tests in the AppSec integration tests in dd-trace-php that are very likely caused by this and also possible system-tests telemetry tests flakiness that is possibly also related (I have not investigated)

BREAKING CHANGE: removes the shutdown_runtime and shutdown_session sidecar RPCs and removes the is_fork parameter from set_session_config and ddog_sidecar_session_set_config.

@cataphract
cataphract requested review from a team as code owners July 27, 2026 10:09

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

Copy link
Copy Markdown

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: 03fafcbba6

ℹ️ 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 on lines +197 to +198
for runtime in runtimes {
runtime.shutdown();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Clear applications during session shutdown

When shutdown() runs while a RuntimeLease is still alive—a case explicitly supported by release_runtime—the lease retains another RuntimeInfo clone and therefore the shared applications Arc. Consuming the drained clone here does not drop the applications or their remote-config guards because RuntimeInfo::shutdown() only logs, so session teardown leaves subscriptions and stale application state active until every lease eventually disappears. Explicitly clear the applications during shutdown rather than relying on the RuntimeInfo clone being the last owner.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

under the intended lifecycle, stop_session is only called when session_counter for the session_id reaches 0. So the session should not be reclaimed until all the connections, and consequently all the runtime leases on the session are gone. Perhaps this could be made less fragile though -- it is true that after this patch, with both the session and the connections holding strong references to the runtimes, it becomes more likely that some logic error has runtimes outliving their session (and consequently not dropping applications and their resources). Although I'm not sure that the consequences of this on master would be that benign either

@pr-commenter

pr-commenter Bot commented Jul 27, 2026

Copy link
Copy Markdown

Benchmarks

Comparison

Candidate

Candidate benchmark details

Baseline

Baseline benchmark details

@datadog-datadog-prod-us1

datadog-datadog-prod-us1 Bot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Tests

🎉 All green!

🧪 All tests passed
❄️ No new flaky tests detected

🎯 Code Coverage (details)
Patch Coverage: 0.00%
Overall Coverage: 74.58% (-0.02%)

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

@dd-octo-sts

dd-octo-sts Bot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Artifact Size Benchmark Report

aarch64-alpine-linux-musl
Artifact Baseline Commit Change
/aarch64-alpine-linux-musl/lib/libdatadog_profiling.a 87.13 MB 87.13 MB 0% (0 B) 👌
/aarch64-alpine-linux-musl/lib/libdatadog_profiling.so 8.01 MB 8.01 MB 0% (0 B) 👌
aarch64-unknown-linux-gnu
Artifact Baseline Commit Change
/aarch64-unknown-linux-gnu/lib/libdatadog_profiling.a 98.38 MB 98.38 MB 0% (0 B) 👌
/aarch64-unknown-linux-gnu/lib/libdatadog_profiling.so 10.77 MB 10.77 MB 0% (0 B) 👌
libdatadog-x64-windows
Artifact Baseline Commit Change
/libdatadog-x64-windows/debug/dynamic/datadog_profiling_ffi.dll 26.00 MB 26.00 MB 0% (0 B) 👌
/libdatadog-x64-windows/debug/dynamic/datadog_profiling_ffi.lib 89.18 KB 89.18 KB 0% (0 B) 👌
/libdatadog-x64-windows/debug/dynamic/datadog_profiling_ffi.pdb 187.92 MB 187.92 MB 0% (0 B) 👌
/libdatadog-x64-windows/debug/static/datadog_profiling_ffi.lib 978.93 MB 978.93 MB 0% (0 B) 👌
/libdatadog-x64-windows/release/dynamic/datadog_profiling_ffi.dll 8.47 MB 8.47 MB 0% (0 B) 👌
/libdatadog-x64-windows/release/dynamic/datadog_profiling_ffi.lib 89.18 KB 89.18 KB 0% (0 B) 👌
/libdatadog-x64-windows/release/dynamic/datadog_profiling_ffi.pdb 25.05 MB 25.05 MB 0% (0 B) 👌
/libdatadog-x64-windows/release/static/datadog_profiling_ffi.lib 49.84 MB 49.84 MB 0% (0 B) 👌
libdatadog-x86-windows
Artifact Baseline Commit Change
/libdatadog-x86-windows/debug/dynamic/datadog_profiling_ffi.dll 22.61 MB 22.61 MB 0% (0 B) 👌
/libdatadog-x86-windows/debug/dynamic/datadog_profiling_ffi.lib 90.58 KB 90.58 KB 0% (0 B) 👌
/libdatadog-x86-windows/debug/dynamic/datadog_profiling_ffi.pdb 192.51 MB 192.51 MB -0% (-8.00 KB) 👌
/libdatadog-x86-windows/debug/static/datadog_profiling_ffi.lib 968.14 MB 968.14 MB 0% (0 B) 👌
/libdatadog-x86-windows/release/dynamic/datadog_profiling_ffi.dll 6.54 MB 6.54 MB 0% (0 B) 👌
/libdatadog-x86-windows/release/dynamic/datadog_profiling_ffi.lib 90.58 KB 90.58 KB 0% (0 B) 👌
/libdatadog-x86-windows/release/dynamic/datadog_profiling_ffi.pdb 26.91 MB 26.91 MB 0% (0 B) 👌
/libdatadog-x86-windows/release/static/datadog_profiling_ffi.lib 47.43 MB 47.43 MB 0% (0 B) 👌
x86_64-alpine-linux-musl
Artifact Baseline Commit Change
/x86_64-alpine-linux-musl/lib/libdatadog_profiling.a 77.74 MB 77.74 MB 0% (0 B) 👌
/x86_64-alpine-linux-musl/lib/libdatadog_profiling.so 8.91 MB 8.91 MB 0% (0 B) 👌
x86_64-unknown-linux-gnu
Artifact Baseline Commit Change
/x86_64-unknown-linux-gnu/lib/libdatadog_profiling.a 93.20 MB 93.20 MB 0% (0 B) 👌
/x86_64-unknown-linux-gnu/lib/libdatadog_profiling.so 10.84 MB 10.84 MB 0% (0 B) 👌

@cataphract
cataphract force-pushed the glopes/sidecar-runtime-lease branch from d6363b1 to cd97f7c Compare July 27, 2026 16:40
@cataphract cataphract changed the title fix(sidecar): move RuntimeInfo to a shared ownership model fix(sidecar): remove spurious deletion of runtimes on set_session_config Jul 27, 2026
@cataphract

Copy link
Copy Markdown
Contributor Author

/merge

@gh-worker-devflow-routing-ef8351

gh-worker-devflow-routing-ef8351 Bot commented Jul 27, 2026

Copy link
Copy Markdown

View all feedbacks in Devflow UI.

2026-07-27 21:23:06 UTC ℹ️ Start processing command /merge


2026-07-27 21:23:11 UTC ℹ️ MergeQueue: pull request added to the queue

The expected merge time in main is approximately 1h (p90).


2026-07-27 22:03:59 UTC ℹ️ MergeQueue: This merge request was merged

@gh-worker-dd-mergequeue-cf854d
gh-worker-dd-mergequeue-cf854d Bot merged commit f2010b6 into main Jul 27, 2026
109 of 113 checks passed
@gh-worker-dd-mergequeue-cf854d
gh-worker-dd-mergequeue-cf854d Bot deleted the glopes/sidecar-runtime-lease branch July 27, 2026 22:03
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