Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ea823dd

Browse files
IoUring: Only fire IoUringBufferRingExhaustedEvent if we could not (#15474)
expand the ring Motivation: When we use a buffer ring we usually increase its size up to a maximum in batches. Because of this it can happen that we see an ENOBUF but still can increase the number of buffers in the ring, which means we did not hit the hard limit yet. If this happens we should better NOT fire an IoUringBufferRingExhaustedEvent as in reality its not exhausted yet but just not completely filled to the max. Modifications: Only fire IoUringBufferRingExhaustedEvent if we real hit the limit of the number of buffers that we can put in the ring. Result: Less confusing event propagation --------- Co-authored-by: Chris Vest <[email protected]>
1 parent 757296c commit ea823dd

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

transport-classes-io_uring/src/main/java/io/netty/channel/uring/AbstractIoUringStreamChannel.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -431,13 +431,13 @@ protected void readComplete0(byte op, int res, int flags, short data, int outsta
431431
try {
432432
if (res < 0) {
433433
if (res == Native.ERRNO_NOBUFS_NEGATIVE) {
434-
// recv with provider buffer failed, Fire the BufferRingExhaustedEvent to notify users.
435-
// About the failure. If this happens to often the user should most likely increase the
436-
// buffer ring size.
437-
pipeline.fireUserEventTriggered(bufferRing.getExhaustedEvent());
438-
439434
// try to expand the buffer ring by adding more buffers to it if there is any space left.
440-
bufferRing.expand();
435+
if (!bufferRing.expand()) {
436+
// We couldn't expand the ring anymore so notify the user that we did run out of buffers
437+
// without the ability to expand it.
438+
// If this happens to often the user should most likely increase the buffer ring size.
439+
pipeline.fireUserEventTriggered(bufferRing.getExhaustedEvent());
440+
}
441441

442442
// Let's trigger a read again without consulting the RecvByteBufAllocator.Handle as
443443
// we can't count this as a "real" read operation.

transport-classes-io_uring/src/main/java/io/netty/channel/uring/IoUringBufferRing.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,12 @@ private void add(int tail, short bid, int offset, ByteBuf byteBuf) {
159159

160160
/**
161161
* Try to expand by adding more buffers to the ring if there is any space left, this will be done lazy.
162+
*
163+
* @return {@code true} if we can expand the number of buffers in the ring, {@code false} otherwise.
162164
*/
163-
void expand() {
165+
boolean expand() {
164166
needExpand = true;
167+
return allocatedBuffers < buffers.length;
165168
}
166169

167170
private void fill(short startBid, int buffers) {

0 commit comments

Comments
 (0)