Skip to content

Is it safe to call io_uring_for_each_cqe at any time? #927

Answered by ioquatix
ioquatix asked this question in Q&A
Discussion options

You must be logged in to vote

Ah yes, it's shown in the above code: ring_fd = -1 - this is what I do during garbage collection to indicate the ring is closed - this is definitely a bug on my end. My bad.

Here are some more specific details just in case it's helpful for anyone else.

In my test suite, I was creating the io_uring and at the end of the test, it was closed.

However, during the test, I was using a separate thread to actually run the io_uring to check the behaviour of SIGVTALRM/EINTR.

This thread was being leaked, and so the order of operations was:

  1. Create io_uring.
  2. Create thread.
  3. On that thread, wait for events.
  4. Close io_uring.
  5. Thread exiting => io_uring_foreach_cqe was invoked on invalid io_uring.
  6. Fault.

Replies: 2 comments 4 replies

Comment options

You must be logged in to vote
4 replies
@ioquatix
Comment options

@axboe
Comment options

@ioquatix
Comment options

@ioquatix
Comment options

Answer selected by axboe
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants