dakrone/clj-http

Async request goes not work when uploading files greater than 25 KB

YaelKhalman opened this issue · 2 comments

When sending multipart put request with file greater than 25 KB I'm getting Content length is too long: 1300881 exception coming from org.apache.http.entity.mime.MultipartFormEntity.getContent(MultipartFormEntity.java:103)

Stack trace:

failed:645, core$request$reify__18941 (clj_http)
failed:138, BasicFuture (org.apache.http.concurrent)
executionFailed:101, DefaultClientExchangeHandlerImpl (org.apache.http.impl.nio.client)
failed:426, AbstractClientExchangeHandler (org.apache.http.impl.nio.client)
exception:155, HttpAsyncRequestExecutor (org.apache.http.nio.protocol)
produceOutput:310, DefaultNHttpClientConnection (org.apache.http.impl.nio)
onOutputReady:86, InternalIODispatch (org.apache.http.impl.nio.client)
onOutputReady:39, InternalIODispatch (org.apache.http.impl.nio.client)
outputReady:152, AbstractIODispatch (org.apache.http.impl.nio.reactor)
writable:188, BaseIOReactor (org.apache.http.impl.nio.reactor)
processEvent:341, AbstractIOReactor (org.apache.http.impl.nio.reactor)
processEvents:315, AbstractIOReactor (org.apache.http.impl.nio.reactor)
execute:276, AbstractIOReactor (org.apache.http.impl.nio.reactor)
execute:104, BaseIOReactor (org.apache.http.impl.nio.reactor)
run:588, AbstractMultiworkerIOReactor$Worker (org.apache.http.impl.nio.reactor)
run:834, Thread (java.lang)
getContent():103, MultipartFormEntity (org.apache.http.entity.mime), MultipartFormEntity.java
produceContent(ContentEncoder, IOControl):65, EntityAsyncContentProducer (org.apache.http.nio.entity), EntityAsyncContentProducer.java
produceContent(ContentEncoder, IOControl):125, BasicAsyncRequestProducer (org.apache.http.nio.protocol), BasicAsyncRequestProducer.java
produceContent(InternalState, ContentEncoder, IOControl):262, MainClientExec (org.apache.http.impl.nio.client), MainClientExec.java
produceContent(ContentEncoder, IOControl):140, DefaultClientExchangeHandlerImpl (org.apache.http.impl.nio.client), DefaultClientExchangeHandlerImpl.java
outputReady(NHttpClientConnection, ContentEncoder):241, HttpAsyncRequestExecutor (org.apache.http.nio.protocol), HttpAsyncRequestExecutor.java
produceOutput(NHttpClientEventHandler):290, DefaultNHttpClientConnection (org.apache.http.impl.nio), DefaultNHttpClientConnection.java
onOutputReady(DefaultNHttpClientConnection):86, InternalIODispatch (org.apache.http.impl.nio.client), InternalIODispatch.java
onOutputReady(Object):39, InternalIODispatch (org.apache.http.impl.nio.client), InternalIODispatch.java
outputReady(IOSession):152, AbstractIODispatch (org.apache.http.impl.nio.reactor), AbstractIODispatch.java
writable(SelectionKey):188, BaseIOReactor (org.apache.http.impl.nio.reactor), BaseIOReactor.java
processEvent(SelectionKey):341, AbstractIOReactor (org.apache.http.impl.nio.reactor), AbstractIOReactor.java
processEvents(Set):315, AbstractIOReactor (org.apache.http.impl.nio.reactor), AbstractIOReactor.java
execute():276, AbstractIOReactor (org.apache.http.impl.nio.reactor), AbstractIOReactor.java
execute(IOEventDispatch):104, BaseIOReactor (org.apache.http.impl.nio.reactor), BaseIOReactor.java
run():588, AbstractMultiworkerIOReactor$Worker (org.apache.http.impl.nio.reactor), AbstractMultiworkerIOReactor.java
run():834, Thread (java.lang), Thread.java

The 25 kb limitation in MultipartFormEntity#getContent is discussed here.

I filed an issue upstream to investigate the underlying issue. See https://issues.apache.org/jira/browse/HTTPASYNC-163

In the meantime, I've found a workaround to bypass the restriction (pending review)

@YaelKhalman This should work now in 3.11.0. If you have a chance, give it a spin.

Something you do have to aware of is that currently, the Async Client will buffer the Multipart Request in memory. This isn't ideal, and is something we will look at improving as part of the 4.x release.