aleph

Leonid Korogodski 2021-05-19T17:02:17.003300Z

Hey, everyone. I have a reverse proxy that currently uses http-kit, but I want to replace it with aleph because I want to be able to stream large files through the proxy, and http-kit insists on buffering the entire response before sending it back. However, I'm getting the following error:

2021-05-19T10:52:10,976 [aleph-netty-server-event-pool-5] ERROR aleph.http.core - error sending body of type  clojure.lang.PersistentArrayMap 
java.lang.IllegalArgumentException: Don't know how to convert class clojure.lang.PersistentArrayMap into (stream-of io.netty.buffer.ByteBuf)
	at byte_streams$convert.invokeStatic(byte_streams.clj:196)
	at byte_streams$convert.invoke(byte_streams.clj:162)
	at aleph.netty$to_byte_buf_stream.invokeStatic(netty.clj:203)
	at aleph.netty$to_byte_buf_stream.invoke(netty.clj:202)
	at aleph.http.core$send_streaming_body.invokeStatic(core.clj:318)
	at aleph.http.core$send_streaming_body.invoke(core.clj:273)
	at aleph.http.core$eval10167$send_message__10174$fn__10175.invoke(core.clj:535)
	at aleph.http.core$eval10167$send_message__10174.invoke(core.clj:534)
	at aleph.http.server$eval10262$send_response__10267$f__9568__auto____10273.invoke(server.clj:140)
	at aleph.http.server$eval10262$send_response__10267$fn__10275.invoke(server.clj:129)
	at clojure.lang.AFn.run(AFn.java:22)
	at io.netty.util.concurrent.AbstractEventExecutor.safeExecute$$$capture(AbstractEventExecutor.java:164)
	at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java)
	at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:472)
	at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:500)
	at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989)
	at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
	at manifold.executor$thread_factory$reify__4367$f__4368.invoke(executor.clj:47)
	at clojure.lang.AFn.run(AFn.java:22)
	at java.base/java.lang.Thread.run(Thread.java:829)
The code in question is simple:
(http/request {:url          (create-url api request)
               :method       request-method
               :query-params query-params
               :headers      (create-headers request api)
               :body         body
               :as           :stream})
In this particular case, the method is GET, the body is nil, and there are no query params.

Leonid Korogodski 2021-05-19T17:02:44.003700Z

Using 0.4.7-alpha7.

valerauko 2021-05-19T17:31:20.003800Z

what are create-url and create-headers?

2021-05-19T18:06:20.005200Z

looks like that isn't from the request code you shared, but looks like you are trying to return the result of the request as an http response, and the error is from there

Leonid Korogodski 2021-05-19T18:13:09.005700Z

Yes, of course. It's a reverse proxy.

Leonid Korogodski 2021-05-19T18:13:52.005900Z

But why the error?

valerauko 2021-05-19T18:15:33.006Z

i'm suspecting you're accidentally passing a map as a parameter that aleph expects to be a (netty) bytebuf

valerauko 2021-05-19T18:15:49.006200Z

which is probably body by the way

2021-05-19T18:22:04.007Z

whatever request returns isn't something that aleph knows how to serve as an http response

2021-05-19T18:24:10.008800Z

if I had to guess (which I kind of do, because I don't really use aleph ever), request returns a deferred that yields a map, and aleph expects a deferred to just yield bytes to serve

Leonid Korogodski 2021-05-19T18:25:20.009300Z

Yes. Strange that aleph wouldn't handle that.