Skip to content

Conversation

@faviansamatha
Copy link
Contributor

@faviansamatha faviansamatha commented Jan 29, 2026

Description

Sliding expiration cache is not thread safe. When manually testing with 30 threads executing a query and triggering failover with the failover_v2, the following error could be displayed:

aws_advanced_python_wrapper.FailoverSuccessError: [Failover] The active SQL connection has changed due to a connection failure. Please re-configure session state if required.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/app/tests/integration/container/dummy/test_failover_race_condition.py", line 254, in long_running_query
    with AwsWrapperConnection.connect(
  File "/app/aws_advanced_python_wrapper/wrapper.py", line 232, in __exit__
    self.release_resources()
  File "/app/aws_advanced_python_wrapper/wrapper.py", line 220, in release_resources
    self._plugin_service.release_resources()
  File "/app/aws_advanced_python_wrapper/plugin_service.py", line 740, in release_resources
    host_list_provider.release_resources()
  File "/app/aws_advanced_python_wrapper/host_list_provider.py", line 810, in release_resources
    MonitoringRdsHostListProvider._monitors.clear()
  File "/app/aws_advanced_python_wrapper/utils/sliding_expiration_cache.py", line 99, in clear
    for _, cache_item in self._cdict.items():
RuntimeError: dictionary changed size during iteration

items(), keys(), and values() are not thread-safe when a piece of code is iterating over them. They must first be converted to a list.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@faviansamatha faviansamatha force-pushed the fix/sliding-cache branch 2 times, most recently from 96ef448 to 07723b1 Compare January 29, 2026 06:04
@faviansamatha faviansamatha marked this pull request as ready for review January 29, 2026 06:22
@faviansamatha faviansamatha merged commit 216b956 into main Jan 30, 2026
14 of 15 checks passed
@faviansamatha faviansamatha deleted the fix/sliding-cache branch January 30, 2026 01:28
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.

2 participants