Skip to content

Commit 6d3d796

Browse files
committed
stop config reloading through stop event
1 parent 7c7469e commit 6d3d796

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

localstack-core/localstack/services/lambda_/provider.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,15 @@ def on_after_init(self):
383383
def on_before_stop(self) -> None:
384384
# TODO: should probably unregister routes?
385385
self.lambda_service.stop()
386+
# Attempt to signal to the Lambda Debug Mode session object to stop.
387+
try:
388+
lambda_debug_mode_session = LambdaDebugModeSession.get()
389+
lambda_debug_mode_session.signal_stop()
390+
except Exception as ex:
391+
LOG.error(
392+
"Unexpected error encountered when attempting to signal Lambda Debug Mode to stop '%s'.",
393+
ex,
394+
)
386395

387396
@staticmethod
388397
def _get_function(function_name: str, account_id: str, region: str) -> Function:

localstack-core/localstack/utils/lambda_debug_mode/lambda_debug_mode_session.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
from localstack.aws.api.lambda_ import Arn
1010
from localstack.config import LAMBDA_DEBUG_MODE, LAMBDA_DEBUG_MODE_CONFIG_PATH
11-
from localstack.services.plugins import SERVICE_PLUGINS
1211
from localstack.utils.lambda_debug_mode.lambda_debug_mode_config import (
1312
LambdaDebugConfig,
1413
LambdaDebugModeConfig,
@@ -25,6 +24,7 @@ class LambdaDebugModeSession:
2524
_configuration_file_path: Optional[str]
2625
_watch_thread: Optional[Thread]
2726
_initialised_event: Optional[Event]
27+
_stop_event: Optional[Event]
2828
_config: Optional[LambdaDebugModeConfig]
2929

3030
def __init__(self):
@@ -34,6 +34,7 @@ def __init__(self):
3434
self._configuration_file_path = None
3535
self._watch_thread = None
3636
self._initialised_event = None
37+
self._stop_event = None
3738
self._config = None
3839

3940
# Lambda Debug Mode is not enabled: leave as disabled state and return.
@@ -56,6 +57,9 @@ def __init__(self):
5657
# occur with no Debug configuration.
5758
self._initialised_event = Event()
5859

60+
# Signals when a shutdown signal from the application is registered.
61+
self._stop_event = Event()
62+
5963
self._watch_thread = Thread(
6064
target=self._watch_logic, args=(), daemon=True, name="LambdaDebugModeConfigWatch"
6165
)
@@ -88,6 +92,11 @@ def ensure_running(self) -> None:
8892
exception_str,
8993
)
9094

95+
def signal_stop(self) -> None:
96+
stop_event = self._stop_event
97+
if stop_event is not None:
98+
stop_event.set()
99+
91100
def _load_lambda_debug_mode_config(self):
92101
yaml_configuration_string = None
93102
try:
@@ -145,8 +154,8 @@ def _watch_logic(self) -> None:
145154
self._load_lambda_debug_mode_config()
146155
self._initialised_event.set()
147156

148-
# Monitor for file changes whilst the lambda service is running.
149-
while SERVICE_PLUGINS.is_running("lambda"):
157+
# Monitor for file changes whilst the application is running.
158+
while not self._stop_event.is_set():
150159
time.sleep(1)
151160
epoch_last_modified = self._config_file_epoch_last_modified_or_now()
152161
if epoch_last_modified > epoch_last_loaded:

0 commit comments

Comments
 (0)