Skip to content

Commit

Permalink
Clear aiohttp's SSL context cache
Browse files Browse the repository at this point in the history
  • Loading branch information
ento authored and mindflayer committed Jan 16, 2024
1 parent 01b717d commit efa79d4
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions mocket/mocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@
except ImportError:
pyopenssl_override = False

try: # pragma: no cover
from aiohttp import TCPConnector

aiohttp_make_ssl_context_cache_clear = TCPConnector._make_ssl_context.cache_clear
except (ImportError, AttributeError):
aiohttp_make_ssl_context_cache_clear = None


true_socket = socket.socket
true_create_connection = socket.create_connection
Expand Down Expand Up @@ -548,6 +555,8 @@ def enable(namespace=None, truesocket_recording_dir=None):
if pyopenssl_override: # pragma: no cover
# Take out the pyopenssl version - use the default implementation
extract_from_urllib3()
if aiohttp_make_ssl_context_cache_clear: # pragma: no cover
aiohttp_make_ssl_context_cache_clear()

@staticmethod
def disable():
Expand Down Expand Up @@ -584,6 +593,8 @@ def disable():
if pyopenssl_override: # pragma: no cover
# Put the pyopenssl version back in place
inject_into_urllib3()
if aiohttp_make_ssl_context_cache_clear: # pragma: no cover
aiohttp_make_ssl_context_cache_clear()

@classmethod
def get_namespace(cls):
Expand Down

0 comments on commit efa79d4

Please sign in to comment.