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
4 changes: 2 additions & 2 deletions task-sdk/src/airflow/sdk/api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -814,9 +814,9 @@ def noop_handler(request: httpx.Request) -> httpx.Response:


class Client(httpx.Client):
@classmethod
@lru_cache()
def _get_ssl_context_cached(cls, ca_file: str, ca_path: str | None = None) -> ssl.SSLContext:
@staticmethod
def _get_ssl_context_cached(ca_file: str, ca_path: str | None = None) -> ssl.SSLContext:
"""Cache SSL context to prevent memory growth from repeated context creation."""
ctx = ssl.create_default_context(cafile=ca_file)
if ca_path:
Expand Down
13 changes: 10 additions & 3 deletions task-sdk/tests/task_sdk/api/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1370,10 +1370,10 @@ def handle_request(request: httpx.Request) -> httpx.Response:


class TestSSLContextCaching:
def setup_method(self):
@pytest.fixture(autouse=True)
def clear_ssl_context_cache(self):
Client._get_ssl_context_cached.cache_clear()

def teardown_method(self):
yield
Client._get_ssl_context_cached.cache_clear()

def test_cache_hit_on_same_parameters(self):
Expand All @@ -1382,6 +1382,13 @@ def test_cache_hit_on_same_parameters(self):
ctx2 = Client._get_ssl_context_cached(ca_file, None)
assert ctx1 is ctx2

def test_cache_miss_if_cache_cleared(self):
ca_file = certifi.where()
ctx1 = Client._get_ssl_context_cached(ca_file, None)
Client._get_ssl_context_cached.cache_clear()
ctx2 = Client._get_ssl_context_cached(ca_file, None)
assert ctx1 is not ctx2

def test_cache_miss_on_different_parameters(self):
ca_file = certifi.where()

Expand Down
Loading