]> git.ipfire.org Git - thirdparty/tornado.git/commit
Coroutine exception __context__ leak in python 3 1333/head
authorCarl Sverre <accounts@carlsverre.com>
Thu, 12 Feb 2015 04:00:02 +0000 (20:00 -0800)
committerCarl Sverre <accounts@carlsverre.com>
Thu, 12 Feb 2015 19:33:09 +0000 (11:33 -0800)
commitb2091c407a4483da9dfa8852e080668c0440f428
treee1a14c5c9cdb322ed3084dbcd9103b8541aa19cc
parent9b35208a8102a38ac8f5860a238897b3ab92a422
Coroutine exception __context__ leak in python 3

In Python 3 every exception has an auto-attached __context__ exception if it was
raised while an existing exception was being handled.  This is often a very
useful property and allows users to see the underlying cause of many problems.

However, when dealing with async code via coroutines this feature can suddenly
become a pretty big issue.  Namely, if you generator.throw back into a coroutine
to raise an exception in the correct scope, and that coroutine raises an
exception at a later time you can have nested exceptions which shouldn't
logically be nested.

This patch resolves this issue in the coroutine code by moving the gen.throw
outside of the exception handler.  By doing this the user-code scope is able to
later raise exceptions without worrying about inheriting prior exception
context.
tornado/gen.py
tornado/test/gen_test.py