Hi,

I'm running Django 4.2.7 with Python 3.11 on Ubuntu on my development
setup (so no gunicorn, nginx etc, just standalone Django). I just ran
into the following issue which, once it occurs, causes Django to
become completely unresponsive:

=============
2023-12-19 16:07:02,763 [ERROR] asyncio: Exception in callback
_chain_future.<locals>._set_state(<Future pendi...ask_wakeup()]>,
<Future at 0x...StopIteration>) at /usr/lib/python3.11/async
io/futures.py:381
handle: <Handle _chain_future.<locals>._set_state(<Future
pendi...ask_wakeup()]>, <Future at 0x...StopIteration>) at
/usr/lib/python3.11/asyncio/futures.py:381>
Traceback (most recent call last):
 File "/usr/lib/python3.11/asyncio/events.py", line 80, in _run
   self._context.run(self._callback, *self._args)
 File "/usr/lib/python3.11/asyncio/futures.py", line 383, in _set_state
   _copy_future_state(other, future)
 File "/usr/lib/python3.11/asyncio/futures.py", line 359, in _copy_future_state
   dest.set_exception(_convert_future_exc(exception))
TypeError: StopIteration interacts badly with generators and cannot be
raised into a Future
=============

Once this happens, Django becomes unresponsive (which is what I guess
the dire wording of the exception is hinting at). A trivial reproducer
looks like this:

=============
    def post(self, request: HttpRequest, *args, **kwargs):
        x = next(iter({}.items()))
        ...
=============

Obviously, with an empty dictionary, the next() on the iter()
immediately raises StopIteration, which in turn causes the traceback
above.

In the particular case at hand, the empty dictionary arises for
artificial reasons, and so is not a big concern. However, my code does
have scattered references to next() and my concern is that Django
itself becomes unresponsive.

Am I doing something silly? Is it expected that Django will actually
become unresponsive in such cases?

Advice appreciated.

Thanks, Shaheed

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAHAc2jemn9R%3Ds-%2BC06-5oCoZkEyQ_%2BQUyjY%3D%2BW1%3DOzxK%2BxXuTQ%40mail.gmail.com.

Reply via email to