liburing: `io_uring_peek_batch_cqe` does not populate `cqe` over FFI consistently!

After couple months of segfaults(over interpreter) narrowed the bug down to io_uring_peek_batch_cqe not populating cqe consistently. The first loop always runs fine after its anyone’s guess as to when it will segfault from not populating cqe


while counter := ((io_uring_submit(ring) if io_uring_sq_ready(ring) else 0) + counter - cq_ready):

    # get count of how many event(s) are ready and fill `cqe`
    while not (cq_ready := io_uring_peek_batch_cqe(ring, cqe, counter)):
        io_uring_wait_cqe_nr(ring, cqe, 1)  # wait for at least `1` event to be ready.

    for i in range(cq_ready):
        # do stuff ...

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 23 (20 by maintainers)

Most upvoted comments

Not exactly sure what you mean, I do have faulthandler enabled and output:

============================= test session starts ==============================
platform linux -- Python 3.13.0b1, pytest-8.2.2, pluggy-1.5.0 -- /opt/python/3.13/bin/python3
cachedir: .pytest_cache
rootdir: /.../Liburing/Python/Liburing
configfile: pyproject.toml
collecting ... collected 1 item

test/queue/get_cqe_test.py::test_peek_batch free(): invalid pointer
Fatal Python error: Aborted

Current thread 0x00007e4e7b26c740 (most recent call first):
  File "/.../Liburing/Python/Liburing/test/queue/get_cqe_test.py", line 36 in test_peek_batch
  File "/opt/python/3.13/lib/python3.13/site-packages/_pytest/python.py", line 162 in pytest_pyfunc_call
  File "/opt/python/3.13/lib/python3.13/site-packages/pluggy/_callers.py", line 103 in _multicall
  File "/opt/python/3.13/lib/python3.13/site-packages/pluggy/_manager.py", line 120 in _hookexec
  File "/opt/python/3.13/lib/python3.13/site-packages/pluggy/_hooks.py", line 513 in __call__
  File "/opt/python/3.13/lib/python3.13/site-packages/_pytest/python.py", line 1632 in runtest
  File "/opt/python/3.13/lib/python3.13/site-packages/_pytest/runner.py", line 173 in pytest_runtest_call
  File "/opt/python/3.13/lib/python3.13/site-packages/pluggy/_callers.py", line 103 in _multicall
  File "/opt/python/3.13/lib/python3.13/site-packages/pluggy/_manager.py", line 120 in _hookexec
  File "/opt/python/3.13/lib/python3.13/site-packages/pluggy/_hooks.py", line 513 in __call__
  File "/opt/python/3.13/lib/python3.13/site-packages/_pytest/runner.py", line 241 in <lambda>
  File "/opt/python/3.13/lib/python3.13/site-packages/_pytest/runner.py", line 341 in from_call
  File "/opt/python/3.13/lib/python3.13/site-packages/_pytest/runner.py", line 240 in call_and_report
  File "/opt/python/3.13/lib/python3.13/site-packages/_pytest/runner.py", line 135 in runtestprotocol
  File "/opt/python/3.13/lib/python3.13/site-packages/_pytest/runner.py", line 116 in pytest_runtest_protocol
  File "/opt/python/3.13/lib/python3.13/site-packages/pluggy/_callers.py", line 103 in _multicall
  File "/opt/python/3.13/lib/python3.13/site-packages/pluggy/_manager.py", line 120 in _hookexec
  File "/opt/python/3.13/lib/python3.13/site-packages/pluggy/_hooks.py", line 513 in __call__
  File "/opt/python/3.13/lib/python3.13/site-packages/_pytest/main.py", line 364 in pytest_runtestloop
  File "/opt/python/3.13/lib/python3.13/site-packages/pluggy/_callers.py", line 103 in _multicall
  File "/opt/python/3.13/lib/python3.13/site-packages/pluggy/_manager.py", line 120 in _hookexec
  File "/opt/python/3.13/lib/python3.13/site-packages/pluggy/_hooks.py", line 513 in __call__
  File "/opt/python/3.13/lib/python3.13/site-packages/_pytest/main.py", line 339 in _main
  File "/opt/python/3.13/lib/python3.13/site-packages/_pytest/main.py", line 285 in wrap_session
  File "/opt/python/3.13/lib/python3.13/site-packages/_pytest/main.py", line 332 in pytest_cmdline_main
  File "/opt/python/3.13/lib/python3.13/site-packages/pluggy/_callers.py", line 103 in _multicall
  File "/opt/python/3.13/lib/python3.13/site-packages/pluggy/_manager.py", line 120 in _hookexec
  File "/opt/python/3.13/lib/python3.13/site-packages/pluggy/_hooks.py", line 513 in __call__
  File "/opt/python/3.13/lib/python3.13/site-packages/_pytest/config/__init__.py", line 178 in main
  File "/opt/python/3.13/lib/python3.13/site-packages/_pytest/config/__init__.py", line 206 in console_main
  File "/opt/python/3.13/lib/python3.13/site-packages/pytest/__main__.py", line 7 in <module>
  File "<frozen runpy>", line 88 in _run_code
  File "<frozen runpy>", line 198 in _run_module_as_main

Extension modules: liburing.error, liburing.queue, liburing.time, liburing.socket, liburing.socket_extra, liburing._test, liburing.version, liburing.futex, liburing.probe, liburing.common, liburing.register, liburing.file, liburing.other, liburing.statx, liburing.poll, liburing.os, liburing.syscall, liburing.helper, liburing.xattr (total: 19)

edit: I am not assigning any memory for cqe/sqe so I am not calling free() either, liburing handles memory assigning and freeing