Fork me on GitHub
#aleph
<
2021-05-19
Leonid Korogodski17:05:17

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.

valerauko17:05:20

what are create-url and create-headers?

valerauko18:05:33

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

valerauko18:05:49

which is probably body by the way

Leonid Korogodski17:05:44

Using 0.4.7-alpha7.

hiredman18:05:20

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 Korogodski18:05:09

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

Leonid Korogodski18:05:52

But why the error?

hiredman18:05:04

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

hiredman18:05:10

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 Korogodski18:05:20

Yes. Strange that aleph wouldn't handle that.