io_uring-echo-server icon indicating copy to clipboard operation
io_uring-echo-server copied to clipboard

Returning the buffer on a failed read results in errors

Open barr-israel opened this issue 7 months ago • 1 comments

I have written a simple server based on this echo server and observed the following behavior: when the connection is closed, the read operation gets 0 bytes read and the buffer id 0, and then "returns" it to the available buffers using a "provide" call.
In reality no buffer was given to that read and it is returning buffer 0 without ever getting it, which results in any operation that uses buffer 0 to have unexpected results due to multiple operations sharing the buffer. Removing line 153 fixed this. Might be important: my version uses UNIX sockets and not the INET ones used here.

barr-israel avatar Jun 17 '25 20:06 barr-israel

I was able to reproduce this with INET sockets as well using these few changes: set MAX_CONNECTIONS to 2(to make reproduction faster) add a 5 seconds sleep after a read has been received and before it adds the write request. Run the server Open and close an nc clientwith the server a few times to wrongfully add bid 0 as free multiple times. Open 2 nc clients A,B Enter 1 into A and 2 into B a few times. A will receive 2 after a couple attempts(it appears to happen consistently after the 2nd attempt, which matches with the buffer IDs cycling through the real 0 and 1 buffers before reaching the repeatedly added 0 buffers).

Im certain there is a more automated way and without the sleep to reproduce this, regardless, removing the add_provide_buf line fixes this.

barr-israel avatar Jun 18 '25 11:06 barr-israel