Skip to content

fix: disable remote configuration by default in Lambda#797

Merged
zarirhamza merged 2 commits intomainfrom
zarir.hamza/disable-rc-in-lambda
Apr 15, 2026
Merged

fix: disable remote configuration by default in Lambda#797
zarirhamza merged 2 commits intomainfrom
zarir.hamza/disable-rc-in-lambda

Conversation

@zarirhamza
Copy link
Copy Markdown
Contributor

Summary

Disables remote configuration by default before ddtrace loads, preventing the Unable to create shared memory warning on Lambda cold starts.

Closes #785

Context

Remote configuration in ddtrace relies on /dev/shm for shared memory via multiprocessing.Array. AWS Lambda does not provide /dev/shm, so the allocation fails with FileNotFoundError and logs a warning on every cold start — even when DD_REMOTE_CONFIGURATION_ENABLED=false is explicitly set — because the shared memory allocation happens at import time before the config flag is checked.

This started occurring with ddtrace v4.5.0 due to the single RC subscriber refactor which changed PublisherSubscriberConnector creation from lazy (per-product registration) to eager (at module import time).

Changes

  • datadog_lambda/config.py: Set DD_REMOTE_CONFIGURATION_ENABLED=false in the environment before ddtrace is imported, following the same pattern already used for DD_TRACE_STATS_COMPUTATION_ENABLED and DD_INSTRUMENTATION_TELEMETRY_ENABLED. Respects explicit user overrides — only sets the default if the env var is not already present.

Primary Fix

The primary fix is in dd-trace-py: DataDog/dd-trace-py#17550 — adds an in_aws_lambda() check in PublisherSubscriberConnector.__init__ to skip the shared memory allocation entirely when running in Lambda.

This PR is a defense-in-depth companion that:

  1. Ensures ddconfig._remote_config_enabled is False from the start (the env var defaults to True when unset, and the ASM Lambda guard only overrides it later during initialization)
  2. Prevents the RC poller from ever being enable()d
  3. Follows established conventions in this module for disabling features incompatible with Lambda

Integration Test Snapshots

This change alters ddtrace startup behavior (RC is now False from config init rather than True-then-False after the ASM guard). Integration test snapshots need regenerating via UPDATE_SNAPSHOTS=true.

Test Plan

  • Unit tests pass (all Python versions)
  • Integration test snapshots regenerated

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
@zarirhamza zarirhamza marked this pull request as ready for review April 15, 2026 17:41
@zarirhamza zarirhamza merged commit 39f48d5 into main Apr 15, 2026
104 of 105 checks passed
@zarirhamza zarirhamza deleted the zarir.hamza/disable-rc-in-lambda branch April 15, 2026 17:42
gh-worker-dd-mergequeue-cf854d bot pushed a commit to DataDog/dd-trace-py that referenced this pull request 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](74c3ab43b0) (`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](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

Co-authored-by: zarir.hamza <zarir.hamza@datadoghq.com>
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

2 participants