Closed
Description
We hit an issue where patch_all() was used in a Lambda function - after the 1000th call we saw a RecursionError when calling requests.get()
.
Example:
from aws_xray_sdk.core import patch_all
import requests
import sys
def lambda_handler(event, _context):
for i in range(sys.getrecursionlimit()):
patch_all()
requests.get('https://google.com') # Triggers RecursionError
We should have called patch_all()
outside of the function, but this still feels like a gotcha.
core.patcher._patch
has this code:
def _patch(module_to_patch):
# [...]
if module_to_patch in _PATCHED_MODULES:
log.debug('%s already patched', module_to_patch)
So it recognises the multiple patch, but repatches anyway.
Should _patch
return early if it recognises the patch is already in place?