We are using ahc with much success; it's a great piece of software. However, we have an intermittent issue where threads stall out while reading data.
Our ahc client calls a custom HTTP service, and there is a 3rd-party API which consumes an InputStream when parsing the result. We use a PipedInputStream for the parser; the PipedOutputStream is passed to our AsyncCompletionHandler impl. Every once in awhile, we'll see some stuck threads (this is running in weblogic) with the following trace:
-- Waiting for notification on: java.io.PipedInputStream@ffffffffe3af4840[fat lock]
java.io.PipedInputStream.read(PipedInputStream.java:238)
java.io.PipedInputStream.read(PipedInputStream.java:295)
java.io.BufferedInputStream.read1(BufferedInputStream.java:247)
java.io.BufferedInputStream.read(BufferedInputStream.java:304)
^-- Holding lock: java.io.BufferedInputStream@ffffffffe3ae5f52[thin lock]
sun.nio.cs.StreamDecoder$CharsetSD.readBytes(StreamDecoder.java:397)
sun.nio.cs.StreamDecoder$CharsetSD.implRead(StreamDecoder.java:436)
sun.nio.cs.StreamDecoder.read(StreamDecoder.java:150)
java.io.InputStreamReader.read(InputStreamReader.java:167)
^-- Holding lock: java.io.InputStreamReader@ffffffffe3ae6de7[thin lock]
java.io.Reader.read(Reader.java:122)
com.....ResultParser.parse(ResultParser.java:44)
...
At it's worse, these errors can exhaust file descriptors for the process, but we've only seen that happen once. The problem is very intermittent, and I've been unable to reproduce.
- The PipedOutputStream will be written to by an ahc thread handling the response, including being closed in the onCompleted() or onThrowable() methods.
- The thread handling the request will block in the ResultParser on the input stream (i.e. the PipedInputStream) until EOF.
Does the code look right? Are there any cases where the OutputStream would not be closed?
What I'll try next: upgrade to latest AHC (currently using 1.6.5 which is a little old); check out BodyDeferringAsyncHandler, although it looks pretty similar to what we have.
Thanks for any help,
Tim