python / cpython

The Python programming language
https://www.python.org
Other
63.18k stars 30.25k forks source link

<class 'contextlib._GeneratorContextManager'> returned a result with an error set #76980

Closed 3a02f226-0e25-4f0d-a7cb-79d66a1c129e closed 2 years ago

3a02f226-0e25-4f0d-a7cb-79d66a1c129e commented 6 years ago
BPO 32799
Nosy @serhiy-storchaka, @zhangyangyu
Files
  • Screen Shot 2018-02-08 at 8.28.00 AM.png: Screencapture of error details in sentry
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields: ```python assignee = None closed_at = None created_at = labels = ['type-bug', 'library'] title = " returned a result with an error set" updated_at = user = 'https://bugs.python.org/EliRibble' ``` bugs.python.org fields: ```python activity = actor = 'xiang.zhang' assignee = 'none' closed = False closed_date = None closer = None components = ['Library (Lib)'] creation = creator = 'EliRibble' dependencies = [] files = ['47430'] hgrepos = [] issue_num = 32799 keywords = [] message_count = 6.0 messages = ['311836', '311840', '311851', '313861', '313914', '315556'] nosy_count = 3.0 nosy_names = ['serhiy.storchaka', 'xiang.zhang', 'EliRibble'] pr_nums = [] priority = 'normal' resolution = None stage = None status = 'open' superseder = None type = 'behavior' url = 'https://bugs.python.org/issue32799' versions = ['Python 2.7', 'Python 3.6'] ```

    3a02f226-0e25-4f0d-a7cb-79d66a1c129e commented 6 years ago

    We've had about 200 occurrences of this error in various parts of our code. I have captured stack traces using sentry so I may be able to provide more detail if requested. The ultimate problem is that a SystemError is raised from within contextlib. The message of the SystemError is:

    "\<class 'contextlib._GeneratorContextManager'> returned a result with an error set"

    The code, according to sentry, that is emitting this error is:

    python3.6/contextlib.py in helper at line 159 \<cleanup> """ @wraps(func) def helper(args, *\kwds):

       return \_GeneratorContextManager(func, args, kwds)

    return helper

    I'm reporting this bug primarily because of the documentation at https://docs.python.org/3/library/exceptions.html#SystemError and I'm using CPython

    serhiy-storchaka commented 6 years ago

    Since contextlib._GeneratorContextManager is implemented in Python, it is unlikely that it is a culprit of the error. Do you use any third-party extensions? Likely some extension provoked the error.

    Can you provide a minimal script that reproduces the issue?

    3a02f226-0e25-4f0d-a7cb-79d66a1c129e commented 6 years ago

    To my knowledge, no, we don't use any python extensions. Unless extensions can be installed via pip, in which case I would need to audit our many dependencies to determine if any of them ultimately pull in any extensions as part of a pip install.

    I can't provide a minimal script, no, we don't reproduce it deterministically. Like I said, our application runs all the time and we appear to have about \~200 instances where the problem has been caught by our uncaught exception handling system. The repro of the bug does not appear to have a set correlation with exercise of a particular feature or a particular application state. Given the exception is a thin wrapper around linux syscalls, my guess is something like select(), it's likely the issue has to do with transient network communication problems.

    serhiy-storchaka commented 6 years ago

    What is the full version of Python you used? If this is not 3.6.3 does upgrading to 3.6.3 help? Try also with 3.6.4rc1 and the beta of 3.7.

    Do you use threads, forking, signal handlers? Is it synchronous or asynchronous code? Could you show the code of the function decorated with the contextmanager (or asynccontextmanager) decorator and the code that uses this context manager?

    With such little information we can fix a bug only by accident, when fixing other bugs or during refactoring. And there is a chance that it is already fixed in 3.6.3, 3.6.4rc1 or 3.7.

    3a02f226-0e25-4f0d-a7cb-79d66a1c129e commented 6 years ago

    You can feel free to close the bug - I no longer work for the company that had this problem and I was only reporting the bug because the documentation specifically requested I do so. I don't have the ability now to try upgrading the version of Python to see if it resolves the problem. I also no longer have access to the stack traces.

    The code in question did not use threading, forking or signal handlers and I no longer have the rights to provide the wrapped code.

    zhangyangyu commented 6 years ago

    Our application also runs into this error today and this is an occasional error that we didn't encounter before and can't reproduce currently. Although our application uses the outdated 2.7.5 but the problem looks similar. Our exception traceback points to PyCell_Get:

    ... RROR nova.api.openstack File "/opt/cloud/services/cascading-nova/venv/lib/python2.7/site-packages/keystonemiddleware/auth_token/_cache.py", line 222, in get RROR nova.api.openstack with self._cache_pool.reserve() as cache: RROR nova.api.openstack File "/usr/lib64/python2.7/contextlib.py", line 84, in helper RROR nova.api.openstack return GeneratorContextManager(func(args, *\kwds)) RROR nova.api.openstack SystemError: /home/abuild/rpmbuild/BUILD/Python-2.7.5/Objects/cellobject.c:24: bad argument to internal function

    kumaraditya303 commented 2 years ago

    Python 2.7.5 is not supported. Create a new issue with reproduce if this happens on supported Python versions.