fix: defer boot_agent until after eventlet monkey_patch to prevent recursion error - #903
CagriYonca wants to merge 1 commit into
Conversation
pvital
left a comment
There was a problem hiding this comment.
Great work @CagriYonca.
I have a few considerations.
c0dbd67 to
38966d8
Compare
4a4d649 to
f9bc0fd
Compare
…cursion error Signed-off-by: Cagri Yonca <cagri@ibm.com>
f9bc0fd to
eea8860
Compare
|
Update after comments:
|
Problem & Root Cause
When running under Gunicorn with the
eventletworker class, Instana's early auto-instrumentation eagerly imports third-party libraries in the master process beforeeventlet.monkey_patchexecutes.Modules such as
urllib3andpymongocapture module-level references to the unpatchedssl.SSLContext. When Eventlet subsequently patches thesslmodule,ssl.SSLContextis replaced with its green subclass. Initializing SSL connections later causessuperlookups inside property setters to resolve the global green subclass instead of the original class, resulting in an infinite recursion and aRecursionError.Solution
This PR defers
boot_agentexecution wheneventletis present in the environment:eventlet.monkey_patchusingwrapt.boot_agentand all eager instrumentation imports until aftereventlet.monkey_patchcompletes in the forked worker process.Changes
src/instana/__init__.py: Added_defer_boot_until_eventlet_patchto defer agent boot until worker post-patch.tests/frameworks/test_eventlet_autotrace.py: Added unit tests covering deferred boot registration, worker execution, and arbiter suppression.