Skip to content

fix(rc): skip shared memory allocation in AWS Lambda#17550

Merged
gh-worker-dd-mergequeue-cf854d[bot] merged 3 commits intomainfrom
zarir.hamza/fix-lambda-shared-memory-warning
Apr 15, 2026
Merged

fix(rc): skip shared memory allocation in AWS Lambda#17550
gh-worker-dd-mergequeue-cf854d[bot] merged 3 commits intomainfrom
zarir.hamza/fix-lambda-shared-memory-warning

Conversation

@zarirhamza
Copy link
Copy Markdown
Contributor

@zarirhamza zarirhamza commented Apr 15, 2026

Summary

Fixes the Unable to create shared memory. Features relying on remote configuration will not work as expected. warning that appears on every Lambda cold start since ddtrace v4.5.0.

Closes DataDog/datadog-lambda-python#785

Root Cause

The single RC subscriber refactor (v4.5.0) moved PublisherSubscriberConnector creation into RemoteConfigClient.__init__, making it eagerly constructed when the module-level remoteconfig_poller singleton is instantiated at import time. Before that refactor, connectors were created lazily per-product registration and were never created in Lambda because remote config is disabled there.

AWS Lambda does not provide /dev/shm, so the multiprocessing.Array allocation always fails with FileNotFoundError, logging the warning even though:

  • DD_REMOTE_CONFIGURATION_ENABLED=false is set
  • The ASM settings already disable remote config for Lambda (asm.py:284)

Both guards run after the singleton is already created — too late to prevent the allocation attempt.

Changes

  • ddtrace/internal/remoteconfig/_connectors.py: Check in_aws_lambda() in PublisherSubscriberConnector.__init__ before attempting shared memory allocation. When in Lambda, skip directly to _DummySharedArray without logging a warning (this is expected behavior, not an error).
  • tests/internal/remoteconfig/test_remoteconfig_connector.py: Add test verifying the connector uses _DummySharedArray when AWS_LAMBDA_FUNCTION_NAME is set.

Safety

Using _DummySharedArray in Lambda is safe because:

  • .value is the only attribute accessed on the shared array — _DummySharedArray satisfies the full duck-typing contract
  • connector.read() returns [] when .value is b"", which is handled gracefully by the subscriber dispatch chain (_dispatch_to_products calls periodic() on callbacks then returns early)
  • The RC poller never starts in Lambda (enable() returns False), so no data is ever written to the connector
  • All RC callbacks (ASM, DI, APM Tracing, Tracer Flare, Feature Flags) handle empty/no-op RC data gracefully
  • This is the same _DummySharedArray already used as the FileNotFoundError fallback — we just reach it earlier and without the warning

Companion PR

Defense-in-depth change in datadog-lambda-python: DataDog/datadog-lambda-python#797 (sets DD_REMOTE_CONFIGURATION_ENABLED=false before ddtrace loads)

Test Plan

  • Existing test_remoteconfig_connector.py tests pass (non-Lambda paths unchanged)
  • New test_connector_uses_dummy_shared_array_in_aws_lambda test passes
  • Verify no Unable to create shared memory warning in Lambda cold start logs

Copy link
Copy Markdown
Member

@brettlangdon brettlangdon left a comment

Choose a reason for hiding this comment

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

needs a release note

@cit-pr-commenter-54b7da
Copy link
Copy Markdown

cit-pr-commenter-54b7da bot commented Apr 15, 2026

Codeowners resolved as

ddtrace/internal/remoteconfig/_connectors.py                            @DataDog/remote-config @DataDog/apm-core-python
releasenotes/notes/fix-lambda-shared-memory-warning-4873867125814623.yaml  @DataDog/apm-python
tests/internal/remoteconfig/test_remoteconfig_connector.py              @DataDog/remote-config @DataDog/apm-core-python

AWS Lambda does not provide /dev/shm, so the multiprocessing.Array
allocation in PublisherSubscriberConnector always fails with
FileNotFoundError. Since the single-subscriber refactor (74c3ab4)
the connector is eagerly created at import time via the module-level
remoteconfig_poller singleton, causing a noisy warning on every cold
start even when remote configuration is disabled.

Check in_aws_lambda() before attempting the allocation and fall back
directly to _DummySharedArray without logging a warning, since this
is expected behavior in Lambda — not an error condition.

Resolves: DataDog/datadog-lambda-python#785
@datadog-prod-us1-6
Copy link
Copy Markdown

datadog-prod-us1-6 bot commented Apr 15, 2026

✅ Tests

🎉 All green!

❄️ No new flaky tests detected
🧪 All tests passed

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 2d83d87 | Docs | Datadog PR Page | Was this helpful? React with 👍/👎 or give us feedback!

zarirhamza added a commit to DataDog/datadog-lambda-python that referenced this pull request Apr 15, 2026
Remote configuration relies on /dev/shm for shared memory, which is
unavailable in AWS Lambda. Set DD_REMOTE_CONFIGURATION_ENABLED=false
before ddtrace loads (following the same pattern used for
DD_TRACE_STATS_COMPUTATION_ENABLED and
DD_INSTRUMENTATION_TELEMETRY_ENABLED) so the tracer knows RC is
disabled from the start.

This is a defense-in-depth companion to the primary fix in dd-trace-py
(DataDog/dd-trace-py#17550) which skips the shared memory allocation
entirely when in_aws_lambda() is detected.

Integration test snapshots will need regenerating since ddtrace startup
behavior changes slightly when RC is disabled from the start vs
disabled later by the ASM Lambda guard.

Resolves: #785
Comment thread releasenotes/notes/fix-lambda-shared-memory-warning-4873867125814623.yaml Outdated
Co-authored-by: Brett Langdon <brett.langdon@datadoghq.com>
@gh-worker-dd-mergequeue-cf854d gh-worker-dd-mergequeue-cf854d bot merged commit 95f764d into main Apr 15, 2026
593 of 595 checks passed
@gh-worker-dd-mergequeue-cf854d gh-worker-dd-mergequeue-cf854d bot deleted the zarir.hamza/fix-lambda-shared-memory-warning branch April 15, 2026 18:51
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.

Lambda Unable to create shared memory warnings

3 participants