Commit 95f764d
authored
fix(rc): skip shared memory allocation in AWS Lambda (#17550)
## 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>1 parent 1996620 commit 95f764d
3 files changed
Lines changed: 36 additions & 13 deletions
File tree
- ddtrace/internal/remoteconfig
- releasenotes/notes
- tests/internal/remoteconfig
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
59 | 49 | | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
60 | 66 | | |
61 | 67 | | |
62 | 68 | | |
| |||
Lines changed: 5 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
Lines changed: 12 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
71 | 83 | | |
72 | 84 | | |
73 | 85 | | |
| |||
0 commit comments