Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 19 additions & 13 deletions ddtrace/internal/remoteconfig/_connectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,26 @@ class PublisherSubscriberConnector:
"""

def __init__(self):
try:
self.data = get_mp_context().Array("c", SHARED_MEMORY_SIZE, lock=False)
# FileNotFoundError: /dev/shm may not exist or be inaccessible.
# ImportError: multiprocessing.Array imports multiprocessing.sharedctypes,
# which imports ctypes and requires the _ctypes C extension module. Some
# environments (e.g. Alpine Linux, minimal Docker images, or custom
# Python builds without libffi) do not provide _ctypes and raise
# ModuleNotFoundError.
# See: https://app.datadoghq.com/error-tracking/issue/25b34008-bb9f-11f0-abbd-da7ad0900002
except (FileNotFoundError, ImportError):
log.warning(
"Unable to create shared memory. Features relying on remote configuration will not work as expected."
)
from ddtrace.internal.serverless import in_aws_lambda

if in_aws_lambda():
self.data = _DummySharedArray()
else:
try:
self.data = get_mp_context().Array("c", SHARED_MEMORY_SIZE, lock=False)
# FileNotFoundError: /dev/shm may not exist or be inaccessible.
# ImportError: multiprocessing.Array imports multiprocessing.sharedctypes,
# which imports ctypes and requires the _ctypes C extension module. Some
# environments (e.g. Alpine Linux, minimal Docker images, or custom
# Python builds without libffi) do not provide _ctypes and raise
# ModuleNotFoundError.
# See: https://app.datadoghq.com/error-tracking/issue/25b34008-bb9f-11f0-abbd-da7ad0900002
except (FileNotFoundError, ImportError):
log.warning(
"Unable to create shared memory. "
"Features relying on remote configuration will not work as expected."
)
self.data = _DummySharedArray()
# Checksum attr validates if the Publisher send new data
self.checksum = -1
# shared_data_counter attr validates if the Subscriber send new data
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
fixes:
- |
lambda: Fixes a spurious ``Unable to create shared memory`` warning
on every AWS Lambda cold start.
12 changes: 12 additions & 0 deletions tests/internal/remoteconfig/test_remoteconfig_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,18 @@ def test_connector_fallback_on_array_creation_failure():
assert isinstance(connector.data, _DummySharedArray)


def test_connector_uses_dummy_shared_array_in_aws_lambda(monkeypatch):
"""In AWS Lambda, shared memory (/dev/shm) is unavailable. The connector
should skip the allocation attempt entirely and use _DummySharedArray
without logging a warning.
"""
from ddtrace.internal.remoteconfig._connectors import _DummySharedArray

monkeypatch.setenv("AWS_LAMBDA_FUNCTION_NAME", "my-function")
connector = PublisherSubscriberConnector()
assert isinstance(connector.data, _DummySharedArray)


global_connector = PublisherSubscriberConnector()


Expand Down
Loading