Skip to content

Comments

Fix: Close Open Socket in Streaming Lambdas#732

Draft
zarirhamza wants to merge 1 commit intomainfrom
zarir/streaming-lambda-fix
Draft

Fix: Close Open Socket in Streaming Lambdas#732
zarirhamza wants to merge 1 commit intomainfrom
zarir/streaming-lambda-fix

Conversation

@zarirhamza
Copy link
Contributor

What does this PR do?

Adds a minimal fix to the custom DogStatsD client by calling socket.unref() when the UDP socket is created in src/metrics/dogstatsd.ts.

This prevents the DogStatsD transport socket from keeping the Node.js event loop alive after invocation work is complete, while preserving existing metric emission behavior.

Motivation

Streaming Lambda functions instrumented with datadog-lambda-js were consistently hanging until timeout when enhanced metrics were enabled (regression observed on layer versions after the v11.125.0 metrics transport refactor).

Root cause analysis pointed to DogStatsD socket lifecycle behavior introduced in that refactor. A one-line unref() is the least invasive mitigation with low blast radius.

Testing Guidelines

  • Reproduced the issue on a streaming Lambda before the change (invocations timed out when enhanced metrics enabled).
  • Deployed the one-line fix and verified streaming invocation now completes successfully.
  • Confirmed enhanced metrics and traces are still flushed by the extension (202 Accepted in extension debug logs).
  • Ran unit tests:
    • yarn test src/metrics/dogstatsd.spec.ts --runInBand
    • yarn test src/metrics/dogstatsd.spec.ts src/metrics/listener.spec.ts --runInBand
    • yarn test src/metrics --runInBand
  • Added/updated unit coverage to assert socket unref() behavior in dogstatsd.spec.ts.

Additional Notes

  • This PR intentionally keeps the fix minimal (single behavioral change in runtime code).
  • No API surface changes.
  • No config/env var changes required.
  • This is targeted as a regression fix rather than a broader metrics transport redesign.

Types of Changes

  • Bug fix
  • New feature
  • Breaking change
  • Misc (docs, refactoring, dependency upgrade, etc.)

Check all that apply

  • This PR's description is comprehensive
  • This PR contains breaking changes that are documented in the description
  • This PR introduces new APIs or parameters that are documented and unlikely to change in the foreseeable future
  • This PR impacts documentation, and it has been updated (or a ticket has been logged)
  • This PR's changes are covered by the automated tests
  • This PR collects user input/sensitive content into Datadog
  • This PR passes the integration tests (ask a Datadog member to run the tests)

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.

1 participant