python-trio / python-trio/trio

KeyError in KqueueIOManager.process_events (TrioInternalError)

Open
#3,500 15 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
7.3k
Forks
431
Avg merge
2d 17h
Merged PRs (30d)
6

Description

We have a PySide6 (Qt) application using Trio in guest mode. We are occasionally seeing the error below:

Traceback (most recent call last):
  File "/Users/dev/spire/.venv/lib/python3.14/site-packages/trio/_core/_run.py", line 2765, in unrolled_run
    runner.io_manager.process_events(events)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^
  File "/Users/dev/spire/.venv/lib/python3.14/site-packages/trio/_core/_io_kqueue.py", line 93, in process_events
    receiver = self._registered[key]
               ~~~~~~~~~~~~~~~~^^^^^
KeyError: (46, -2)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/dev/spire/spire-desktop/src/quicore/asyncio.py", line 142, in event
    event.fn()
    ~~~~~~~~^^
  File "/Users/dev/spire/.venv/lib/python3.14/site-packages/trio/_core/_run.py", line 1752, in guest_tick
    self.done_callback(Error(exc))
    ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^
  File "/Users/dev/spire/spire-desktop/src/quicore/asyncio.py", line 130, in _done_callback
    result = outcome_.unwrap()
  File "/Users/dev/spire/.venv/lib/python3.14/site-packages/outcome/_impl.py", line 213, in unwrap
    raise captured_error
  File "/Users/dev/spire/.venv/lib/python3.14/site-packages/trio/_core/_run.py", line 1746, in guest_tick
    timeout = self.unrolled_run_next_send.send(self.unrolled_run_gen)
  File "/Users/dev/spire/.venv/lib/python3.14/site-packages/outcome/_impl.py", line 185, in send
    return gen.send(self.value)
           ~~~~~~~~^^^^^^^^^^^^
  File "/Users/dev/spire/.venv/lib/python3.14/site-packages/trio/_core/_run.py", line 2945, in unrolled_run
    raise TrioInternalError("internal error in Trio - please file a bug!") from exc
trio.TrioInternalError: internal error in Trio - please file a bug!

Unfortunately, I'm not able to reproduce the error reliably, nor am I certain about where to go looking for the issue. Any insight would be most appreciated.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at trio/_core/_io_kqueue.py:93 in KqueueIOManager.process_events and trace the guest-mode path through trio/_core/_run.py, especially unrolled_run and guest_tick. Seek a reproducible sequence involving the missing (46, -2) key and compare it with the registered events. Done means explaining the KeyError and preventing it from escalating to TrioInternalError, ideally with regression coverage.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend, networking
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.