Skip to content

SLES-2913: prevent named pipe failures from eating the whole thread pool - #231

Merged
apiarian-datadog merged 6 commits into
masterfrom
aleksandr.pasechnik/sles-2913-keep-threads-in-check
Jul 24, 2026
Merged

apiarian-datadog merged 6 commits into
masterfrom
aleksandr.pasechnik/sles-2913-keep-threads-in-check

Conversation

@apiarian-datadog

Copy link
Copy Markdown
Contributor

dogstatsd in Azure App Services with the Windows Extension sometimes fail to correctly get a named pipe. This can happen when the app is hot-reloaded and the previous incarnation of dogstatsd hasn't released the named pipe when the new dogstatsd is starting up. This causes the named pipe writes from the dogstatsd client to fail (permanently, until the app is restarted again).

These failures cause a steady growth of threads as the telemetry timer spawns one every 10 seconds to try to write client telemetry, and the 2 second timeout for each of the 11 stats that the telemetry wants to send compounds to 22 seconds of work. Forever.

This change turns the telemetry timer into one that reschedules itself after every round, instead of spawning one every 10 seconds. It also adds a cooldown for sending telemetry, so that if there's a failure to send, we back off for a bit before trying to send any more.

This is one of a few different patches to address this issue. We also have DataDog/dd-trace-dotnet#8874 for the app service extension process manager and DataDog/datadog-agent#53328 for dogstatsd.

@apiarian-datadog
apiarian-datadog requested a review from a team as a code owner July 8, 2026 14:06
@apiarian-datadog

Copy link
Copy Markdown
Contributor Author

This will also hopefully take care of #219

@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: 2fc929af02

ℹ️ 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 src/StatsdClient/Transport/NamedPipeTransport.cs Outdated
@fdmarc

fdmarc commented Jul 8, 2026

Copy link
Copy Markdown

Let's hope this fixes #219 🤞

@apiarian-datadog

Copy link
Copy Markdown
Contributor Author

validated with https://github.com/DataDog/serverless-examples/pull/205 . works in isolation and in combination.

Comment thread src/StatsdClient/Transport/NamedPipeTransport.cs Outdated
@lucaspimentel
lucaspimentel requested a review from Copilot July 13, 2026 16:01
lucaspimentel
lucaspimentel previously approved these changes Jul 13, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds safeguards to prevent runaway blocking/overlapping behavior in named-pipe sending and telemetry flushing, with new tests to validate the intended throttling and non-overlap behavior.

Changes:

  • Add a cooldown gate to NamedPipeTransport to fail fast after send/connect/write failures.
  • Change telemetry timer to one-shot re-arming to prevent overlapping flushes and thread pool growth.
  • Add unit tests covering named pipe cooldown behavior and telemetry flush overlap/dispose scenarios.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 9 comments.

File Description
tests/StatsdClient.Tests/Transport/NamedPipeTransportTests.cs Adds timing-based tests validating cooldown avoids repeated blocking on connect/write failures.
tests/StatsdClient.Tests/TelemetryTests.cs Adds tests asserting flush callbacks don’t overlap and dispose doesn’t deadlock during an in-flight flush.
src/StatsdClient/Transport/NamedPipeTransport.cs Implements failure cooldown gating and resets cooldown on successful send.
src/StatsdClient/Telemetry.cs Switches to one-shot timer re-arm pattern with locking + disposed flag to prevent overlapping flushes.

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

Comment thread tests/StatsdClient.Tests/Transport/NamedPipeTransportTests.cs
Comment thread tests/StatsdClient.Tests/Transport/NamedPipeTransportTests.cs
Comment thread tests/StatsdClient.Tests/Transport/NamedPipeTransportTests.cs Outdated
Comment thread tests/StatsdClient.Tests/TelemetryTests.cs
Comment thread tests/StatsdClient.Tests/TelemetryTests.cs
Comment thread tests/StatsdClient.Tests/TelemetryTests.cs
Comment thread tests/StatsdClient.Tests/TelemetryTests.cs
Comment thread src/StatsdClient/Telemetry.cs
Comment thread src/StatsdClient/Transport/NamedPipeTransport.cs Outdated
duncanpharvey
duncanpharvey previously approved these changes Jul 14, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 6 comments.

Comment thread src/StatsdClient/Telemetry.cs Outdated
Comment thread src/StatsdClient/Transport/NamedPipeTransport.cs Outdated
Comment thread src/StatsdClient/Transport/NamedPipeTransport.cs
Comment thread tests/StatsdClient.Tests/TelemetryTests.cs Outdated
Comment thread tests/StatsdClient.Tests/Transport/NamedPipeTransportTests.cs
Comment thread tests/StatsdClient.Tests/Transport/NamedPipeTransportTests.cs

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.

Comment thread src/StatsdClient/Telemetry.cs
Comment thread src/StatsdClient/Transport/NamedPipeTransport.cs
Comment thread tests/StatsdClient.Tests/TelemetryTests.cs
Comment thread tests/StatsdClient.Tests/Transport/NamedPipeTransportTests.cs Outdated
Comment thread tests/StatsdClient.Tests/Transport/NamedPipeTransportTests.cs Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

Comment thread tests/StatsdClient.Tests/Transport/NamedPipeTransportTests.cs
Comment thread tests/StatsdClient.Tests/Transport/NamedPipeTransportTests.cs Outdated
Comment thread tests/StatsdClient.Tests/Transport/NamedPipeTransportTests.cs Outdated
Comment thread tests/StatsdClient.Tests/Transport/NamedPipeTransportTests.cs Outdated
@carlosroman

Copy link
Copy Markdown
Contributor

@codex review

@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: 5631eca0d3

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/StatsdClient/Transport/NamedPipeTransport.cs
@apiarian-datadog
apiarian-datadog merged commit 2345136 into master Jul 24, 2026
50 of 51 checks passed
@apiarian-datadog
apiarian-datadog deleted the aleksandr.pasechnik/sles-2913-keep-threads-in-check branch July 24, 2026 14:25
@apiarian-datadog apiarian-datadog mentioned this pull request Jul 24, 2026
3 tasks done
apiarian-datadog added a commit that referenced this pull request Jul 27, 2026
## Release 9.2.1

Changelog and version bump for the 9.2.1 NuGet release.

### Included changes
* [BUGFIX] Prevent named pipe write failures from causing unbounded
thread growth. The telemetry timer now reschedules itself after each
round instead of spawning a new thread every 10s, and backs off after
send failures. See #231.

### Checklist
- [x] Changelog entries are accurate
- [x] Version numbers are correct
- [x] PR approved and ready to merge

Once merged, run `/publish-release` to tag, build, and push to NuGet.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants