Hi Team,

We are using AbstractClassicEntityProducer with a customization of storing
/ computing contentLength as well which works fine if we have small POST
data, but when POST data is big (for example 64 KB), it seems OutPutstream
(internally using ContentOutputStream a wrapper over SharedOutputBuffer of
initial size 1024) is not able to write data (We are using temporary buffer
block of 4kb but still it is not able to write 4KB of data). Is there any
limitation or some configuration problem?

*Code being used*
        SharedOutputBuffer buffer = new SharedOutputBuffer(1024);

        produceData(contentType, new ContentOutputStream(buffer));

protected void produceData(ContentType contentType, OutputStream
outputStream) throws IOException {
        byte[] tmp = new byte[4 * 1024];
        int l = -1;
        while ((l = inputStream.read(tmp)) != -1) {
*            outputStream.write(tmp, 0, l);  <---- This is where request
hangs / waits*
        }
}

*HTTPClient has last line as below*
2023-03-02 21:53:52,710 DEBUG
[org.apache.hc.client5.http.impl.async.HttpAsyncMainClientExec]
ex-0000000004: produce request data

*StackTrace when we shutdown connection manager*
 java.io.InterruptedIOException
at
org.apache.hc.core5.http.nio.support.classic.SharedOutputBuffer.waitFlush(SharedOutputBuffer.java:160)
at
org.apache.hc.core5.http.nio.support.classic.SharedOutputBuffer.write(SharedOutputBuffer.java:95)
at
org.apache.hc.core5.http.nio.support.classic.ContentOutputStream.write(ContentOutputStream.java:61)
at com.apache.httpclient.entity.AsyncRequestEntity.produceData(Unknown
Source)
at com.apache.httpclient.entity.AsyncRequestEntity.produce(Unknown Source)
at
org.apache.hc.core5.http.nio.support.BasicRequestProducer.produce(BasicRequestProducer.java:104)
at
org.apache.hc.client5.http.impl.async.InternalAbstractHttpAsyncClient$2.produce(InternalAbstractHttpAsyncClient.java:260)
at
org.apache.hc.client5.http.impl.async.HttpAsyncMainClientExec$1.produce(HttpAsyncMainClientExec.java:163)
at
org.apache.hc.client5.http.impl.async.LoggingAsyncClientExchangeHandler.produce(LoggingAsyncClientExchangeHandler.java:90)
at
org.apache.hc.core5.http.impl.nio.ClientHttp1StreamHandler.commitRequest(ClientHttp1StreamHandler.java:171)
at
org.apache.hc.core5.http.impl.nio.ClientHttp1StreamHandler.lambda$produceOutput$0(ClientHttp1StreamHandler.java:183)
at
org.apache.hc.client5.http.impl.async.LoggingAsyncClientExchangeHandler.lambda$produceRequest$0(LoggingAsyncClientExchangeHandler.java:76)
at
org.apache.hc.client5.http.impl.async.HttpAsyncMainClientExec$1.produceRequest(HttpAsyncMainClientExec.java:150)
at
org.apache.hc.client5.http.impl.async.LoggingAsyncClientExchangeHandler.produceRequest(LoggingAsyncClientExchangeHandler.java:71)
at
org.apache.hc.core5.http.impl.nio.ClientHttp1StreamHandler.produceOutput(ClientHttp1StreamHandler.java:183)
at
org.apache.hc.core5.http.impl.nio.ClientHttp1StreamDuplexer.execute(ClientHttp1StreamDuplexer.java:326)
at
org.apache.hc.core5.http.impl.nio.AbstractHttp1StreamDuplexer.processCommands(AbstractHttp1StreamDuplexer.java:239)
at
org.apache.hc.core5.http.impl.nio.AbstractHttp1StreamDuplexer.onOutput(AbstractHttp1StreamDuplexer.java:386)
at
org.apache.hc.core5.http.impl.nio.AbstractHttp1IOEventHandler.outputReady(AbstractHttp1IOEventHandler.java:73)
at
org.apache.hc.core5.http.impl.nio.ClientHttp1IOEventHandler.outputReady(ClientHttp1IOEventHandler.java:41)
at
org.apache.hc.client5.http.impl.async.LoggingIOSession$1.outputReady(LoggingIOSession.java:243)
at
org.apache.hc.core5.reactor.ssl.SSLIOSession.encryptData(SSLIOSession.java:639)
at
org.apache.hc.core5.reactor.ssl.SSLIOSession.access$400(SSLIOSession.java:74)
at
org.apache.hc.core5.reactor.ssl.SSLIOSession$1.outputReady(SSLIOSession.java:208)
at
org.apache.hc.core5.reactor.InternalDataChannel.onIOEvent(InternalDataChannel.java:152)
at
org.apache.hc.core5.reactor.InternalChannel.handleIOEvent(InternalChannel.java:51)
at
org.apache.hc.core5.reactor.SingleCoreIOReactor.processEvents(SingleCoreIOReactor.java:178)
at
org.apache.hc.core5.reactor.SingleCoreIOReactor.doExecute(SingleCoreIOReactor.java:127)
at
org.apache.hc.core5.reactor.AbstractSingleCoreIOReactor.execute(AbstractSingleCoreIOReactor.java:86)
at org.apache.hc.core5.reactor.IOReactorWorker.run(IOReactorWorker.java:44)
at java.lang.Thread.run(Thread.java:748)

*Another observation is after connecting to a server, the request is not
getting timed out even after 30 minutes as well in the above scenario
(i.e., Large POST Data). DefaultRequestConfig ResponseTimeout is being set
to 5 seconds and even DefaultConnectionConfig ConnectionTimeout and
SocketTimeout also being set to 180000 milliseconds (ie., 3 minutes) and
also same value is being set to IOReactorConfig SoTimeout as well.  Is
there any other setting which is missing which is causing this behavior?*

*HTTPClient log extract*
2023-03-02 21:31:51,187 DEBUG
[org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManager]
ep-0000000001 connecting endpoint to https://server.us.com (180000
MILLISECONDS)

2023-03-02 21:31:55,964 DEBUG
[org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManager]
ep-0000000001 connection c-0000000000 can be kept alive for 3 MINUTES

--
Cheers,
S. Sreenivas

Reply via email to