GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Netty is throwing NoSuchElementException on 4.1.118.Final during AsyncHttpClient calls. · Issue #14839 · netty/netty

Netty is throwing NoSuchElementException on 4.1.118.Final during AsyncHttpClient calls. #14839

New issue
Copy link
New issue
Copy link
Closed
#17438
Closed
Netty is throwing NoSuchElementException on 4.1.118.Final during AsyncHttpClient calls.#14839
#17438
Copy link
Milestone
4.2.19.Final

Description

@bbakerman
bbakerman
opened on Feb 19, 2025
Issue body actions

I am using https://github.com/AsyncHttpClient/async-http-client 3.0.1 which uses Netty 4.1.118.Final .

I can periodically see the following exception when the channel is flushed

Caused by: java.util.NoSuchElementException: null
	at java.base/java.util.ArrayDeque.removeFirst(ArrayDeque.java:362)
	at java.base/java.util.ArrayDeque.remove(ArrayDeque.java:523)
	at io.netty.handler.stream.ChunkedWriteHandler.doFlush(ChunkedWriteHandler.java:287)
	at io.netty.handler.stream.ChunkedWriteHandler.flush(ChunkedWriteHandler.java:146)
	at io.netty.channel.AbstractChannelHandlerContext.invokeFlush0(AbstractChannelHandlerContext.java:937)

in IDEA I see this stack trace leading to this

doFlush:287, ChunkedWriteHandler (io.netty.handler.stream)
flush:146, ChunkedWriteHandler (io.netty.handler.stream)
invokeFlush0:937, AbstractChannelHandlerContext (io.netty.channel)
invokeWriteAndFlush:957, AbstractChannelHandlerContext (io.netty.channel)
write:982, AbstractChannelHandlerContext (io.netty.channel)
writeAndFlush:950, AbstractChannelHandlerContext (io.netty.channel)
writeAndFlush:969, DefaultChannelPipeline (io.netty.channel)
writeAndFlush:310, AbstractChannel (io.netty.channel)
write:87, NettyBodyBody (org.asynchttpclient.netty.request.body)
writeRequest:404, NettyRequestSender (org.asynchttpclient.netty.request)
writeRequest:78, NettyConnectListener (org.asynchttpclient.netty.channel)
onSuccess:150, NettyConnectListener (org.asynchttpclient.netty.channel)
onSuccess:91, NettyChannelConnector$1 (org.asynchttpclient.netty.channel)
operationComplete:28, SimpleChannelFutureListener (org.asynchttpclient.netty)
operationComplete:22, SimpleChannelFutureListener (org.asynchttpclient.netty)
notifyListener0:590, DefaultPromise (io.netty.util.concurrent)
notifyListeners0:583, DefaultPromise (io.netty.util.concurrent)
notifyListenersNow:559, DefaultPromise (io.netty.util.concurrent)
notifyListeners:492, DefaultPromise (io.netty.util.concurrent)
setValue0:636, DefaultPromise (io.netty.util.concurrent)
setSuccess0:625, DefaultPromise (io.netty.util.concurrent)
trySuccess:105, DefaultPromise (io.netty.util.concurrent)
trySuccess:84, DefaultChannelPromise (io.netty.channel)
fulfillConnectPromise:305, AbstractNioChannel$AbstractNioUnsafe (io.netty.channel.nio)
finishConnect:340, AbstractNioChannel$AbstractNioUnsafe (io.netty.channel.nio)
processSelectedKey:784, NioEventLoop (io.netty.channel.nio)
processSelectedKeysOptimized:732, NioEventLoop (io.netty.channel.nio)
processSelectedKeys:658, NioEventLoop (io.netty.channel.nio)
run:562, NioEventLoop (io.netty.channel.nio)
run:998, SingleThreadEventExecutor$4 (io.netty.util.concurrent)
run:74, ThreadExecutorMap$2 (io.netty.util.internal)
run:30, FastThreadLocalRunnable (io.netty.util.concurrent)
run:840, Thread (java.lang)

Debugging reveals that this code assumes that queue has a value when in fact it does not

                if (endOfInput) {
                    // We need to remove the element from the queue before we call writeAndFlush() as this operation
                    // may cause an action that also touches the queue.
                    queue.remove();
                }

it seems to need a if (! queue.isEmpty()) guard on it

Seems related to #11046 but not the same issue.

I tried to make a reproduction but could not - but in our in house application a certain class of interaction causes this every time.

I have also tried on 4.2.0-RC2 and I get the same problem.

Activity

  1. normanmaurer commented on Feb 19, 2025

    @normanmaurer
    normanmaurer
    on Feb 19, 2025
    Member
    More actions

    I don't think the guard is the correct thing todo here... From a quick look it sounds more like something that is caused by reentrancy. Let me dig a bit deeper.

  2. bbakerman commented on Mar 9, 2025

    @bbakerman
    bbakerman
    on Mar 9, 2025
    Author
    More actions

    I also suspect reentrancy - we have code paths here in our integration tests that work well and then kinda the same code not working and I think its about how the connections get closed and what events are firing and when

  3. yawkat commented on Mar 10, 2025

    @yawkat
    yawkat
    on Mar 10, 2025
    Contributor
    More actions

    Which ChunkedInput implementation is triggering this?

  4. wuxiansen commented on Mar 13, 2025

    @wuxiansen
    wuxiansen
    on Mar 13, 2025
    Contributor
    More actions

    When endOfInput is true, it means the entire data stream has been processed, and the queue might already be empty, so there's no need to handle it. Just wrap queue.remove() into a method like this:

    private void removeIfNotEmpty() {  
        if (!queueIsEmpty()) {  
            queue.remove();  
        }  
    }

    Replace queue.remove() with removeIfNotEmpty() in the doFlush method. This way, we only remove an item when the queue isn't empty.

    @normanmaurer @bbakerman

  5. yawkat commented on Mar 17, 2025

    @yawkat
    yawkat
    on Mar 17, 2025
    Contributor
    More actions

    While that would certainly solve this error, it would be nice to understand why the queue is empty in the first place, in case the reentrancy causes other issues. Every remove is preceded by a successful peek.

    Reacted by wuxiansen
  6. normanmaurer commented on Mar 17, 2025

    @normanmaurer
    normanmaurer
    on Mar 17, 2025
    Member
    More actions

    Yeah... I need to understand first why it happens, just adding a null check does not sound right

    Reacted by wuxiansen
  7. bbakerman commented on Apr 10, 2025

    @bbakerman
    bbakerman
    on Apr 10, 2025
    Author
    More actions

    While that would certainly solve this error, it would be nice to understand why the queue is empty in the first place, in case the reentrancy causes other issues. Every remove is preceded by a successful peek.

    Sorry I cant make a simple reproduction - I tried and it never happens - but in our complex system (The Atlassian GraphQl gateway project) we can make it happen in our integration tests all the time - not on every request but on certain requests

    We are blocked in getting to 3.x because of this bug. We have a VULN (on the cookie jar) problem calling us to go to 3.x

  8. normanmaurer commented on Nov 14, 2025

    @normanmaurer
    normanmaurer
    on Nov 14, 2025
    Member
    More actions

    @bbakerman can I somehow run this integration tests ?

  9. normanmaurer
    closed this as completedin #17438on Sep 16, 2026
  10. normanmaurer
    added this to the 4.2.19.Final milestone on Sep 16, 2026
  11. pull
    added a commit that references this issue on Sep 16, 2026

    Guard ChunkedWriteHandler.doFlush() against re-entrant invocation fro…

    3061561
  12. normanmaurer
    added 2 commits that reference this issue on Sep 16, 2026

    Auto-port 4.1: Guard ChunkedWriteHandler.doFlush() against re-entrant…

    2550ea3

    Port: Guard ChunkedWriteHandler.doFlush() against re-entrant invocati…

    3ac1c84
  13. lltopk
    added a commit that references this issue on Oct 24, 2026

    Auto-port 4.1: Guard ChunkedWriteHandler.doFlush() against re-entrant…

    e3029a1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      • 4.2.19.Final

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.