New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bug: tornado "in io loop" logic (python2.7) #1353
Comments
@zhammer thanks for digging into this! Haven't got a chance to read through this thoroughly, but just wanted to give a quick shout-out 😄 It does seem like it's a bug that simply making a new ioloop destroys the current context 😕. |
hey @Kyle-Verhoog ! i just saw this in the 0.37.0 release notes:
is there a PR that fixed this issue? |
Thanks again for the report Zach, I'm going to close this issue out as I don't think we're going to get to this with it being a Python 2.7-specific issue. Please reopen if it's something you'd like to addressed! |
(disclaimer: i don't think this really deserves a fix but want to flag for the team and justify my venturing down this rabbit hole)
bug
discovered some interesting behavior with the tornado stack context for python2.7, where just making a
tornado.ioloop.IOLoop
in synchronous code destroyed my current ddtrace context.on further investigation i found that a lot of
TracerStackContext
relies onTracerStackContext._has_io_loop
, which according to the documentation should tell us if we're "inside" an event loop:dd-trace-py/ddtrace/contrib/tornado/stack_context.py
Lines 72 to 74 in 3129a40
from what i can tell, that logic doesn't check if we're in an event loop, it just checks if there is an event loop. that's why calling
IOLoop.current()
confuses the script I posted:TracerStackContext
thinks we're in synchronous code and grabs a context from threadlocalcontext (which itself creates a context if one doesn't exist)IOLoop.current()
, we're still in synchronous code, but there is an event loop soTracerStackContext
thinks we're in an event loop and tries to get a context from the tornado stateNone
since we never entered theTracerStackContext
fix attempt
i experimented with a fix here: master...seatgeek:zh-tornado-loop following some discussion on this tornado issue: tornadoweb/tornado#2070
ironically i actually prefer the current behavior (where
TracerStackContext
always thinks it's in an IOLoop if there is one) so you can more easily do sync -> async propagation like thisregardless i wanted to raise to you all in case other folks get confused.
The text was updated successfully, but these errors were encountered: