BusError in uvloop within loop extract_stack for nested async_generators
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 35/100
Direzione di ricerca
Riproduci il caso di async_generator annidato su Python 3.12.4 e macOS con la modalità di debug di uvloop abilitata, usando il report dello stack fornito come riferimento. Ispeziona uvloop/handles/handle.pyx e uvloop/cbhandles.pyx intorno a extract_stack, quindi determina la causa del Bus Error e verifica che il crash sia risolto senza disabilitare la modalità di debug.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
- uvloop version:
- 0.19.0 (tested 0.17.0 to 0.19.0)
- Python version: 3.12.4
- Platform: OSX Ventura 13.4/ Darwin 22.5.0
- Can you reproduce the bug with
PYTHONASYNCIODEBUGin env?: - This bug only occurs if
-X devorPYTHONDEVMODE=1orPYTHONASYNCIODEBUG=1orloop.set_debug(True) - Does uvloop behave differently from vanilla asyncio? How?:
- Vanilla asyncio and uvloop with
loop.set_debug(False)do not crash in nested async_generator.asendcalls
I have a pattern called DeferredExecutor which basically allows one to write:
class Foo:
@database(transaction=True, iterable=False)
async def save(self, *args, **kwargs):
# /snip
rows = yield DeferredQuery("some sql")
assert isinstance(rows, tuple)
yield Return(...)
And have it be wrapped by a decorator that will call the async_generator, run the deferred queries against a DB and .asend( the result back into the generator, which will throw an StopAsyncIteration at the conclusion of the generator, and allows me to catch it and end the generators execution.
I am getting my database access object library to run on Python 3.12 (jumping from Python 3.7).
However, on Python 3.12, a particular integration test that uses a particularly reduced implementation:
class Tenant:
@database(iterable=False, transaction=True)
async def invite_users(cls, *tenant_user_pairs, instance=None):
invites = (instance or cls).create_invites_for(*tenant_user_pairs)
gen_event_loop = Invite.save.raw_iterable(*invites)
result = None
while True:
result = await gen_event_loop.asend(result)
if isinstance(result, Return):
break
result = yield result
yield result # StopAsyncIteration gets thrown here
causes uvloop to crash with a Bus Error on OSX but only when loop.set_debug(True) (which is autoset via the environment variables or interpreter devmode)
Regular asyncio, debug or not, works just fine. If I patch the EventLoopPolicy to.set_debug(False) like:
def patch_uvloop():
if uvloop_version_info < (99, 99, 99) and platform.system() == 'Darwin':
cls = uvloop.EventLoopPolicy
if hasattr(cls, '__patched__'):
return cls
class EventLoopPolicy(cls):
__patched__ = True
# ARJ: so uvloop will crash the entire interpreter sometimes
# and the crash originates on OSX. Disable debug mode
# (which keeps it from touching uvloop's extract_stack() which
# explodes badly)
def _loop_factory(self):
loop = super()._loop_factory()
loop.set_debug(False)
return loop
uvloop.EventLoopPolicy = EventLoopPolicy
asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())
Then the crashes never happen.
I do have lldb/gdb and the patience to recompile things with more debugging information (provided I know -how-) but a careful inspection of the following stack trace shows that it explodes after going into the extract_stack function of uvloop:
- https://github.com/MagicStack/uvloop/blob/6c770dc3fbdd281d15c2ad46588c139696f9269c/uvloop/handles/handle.pyx#L118-L119
- https://github.com/MagicStack/uvloop/blob/6c770dc3fbdd281d15c2ad46588c139696f9269c/uvloop/cbhandles.pyx#L14-L15
This does remind me of https://github.com/python/cpython/issues/94694
I wonder if the extract_stack function is tolerant of encountering negative numbers in the offset extraction of the trace.
Stack report:
stack.txt
- Lingua principale
- Cython
- Stelle
- 11.9k
- Fork
- 615
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di MagicStack/uvloop
-
License not clear Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
MagicStack/uvloop#759 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
MagicStack/uvloop#741 · 2 reazioni ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
MagicStack/uvloop#702 · 8 commenti · 9 reazioni ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 25/100
MagicStack/uvloop#766 ·
-
Directly constructed subprocess pipe protocols segfault when callbacks use a non-process owner Aperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 52/100
MagicStack/uvloop#765 ·
Tutte le issue di MagicStack/uvloop
Issue simili
-
[Bug]: Discord Activity titles with emoji are rejected as over 80 characters when they are not Apertaclawsweeper:linked-pr-open clawsweeper:no-new-fix-pr clawsweeper:source-repro impact:message-loss issue-rating: 🦞 diamond lobster maturity:stable P2
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
growthbook/growthbook#7100 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
punkpeye/mcp-remote#369 ·
-
Client customer-reported needs-team-attention question Service Attention WebPubSub
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
Azure/azure-sdk-for-net#63292 · 3 commenti · 1 reazione ·
-
bug p:3-mid pydanty:bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
pydantic/pydantic-ai#8643 · 1 commento ·