aleph

kkruit 2022-10-31T18:08:29.114699Z

Hey all, I'm using aleph to create a tcp client to a service that i'm using and i want the connection to be persistent. It seems like after about 20 seconds of inactivity the connection is closed. Is there any way to make sure the tcp connection doesn't close unless I explicitly close it or the server disconnects for some reason. Could I do something with the bootstrap or pipeline transform options?

(defn start-tcp []
    (log/info "Starting.")
    (let [tcp (->> @config
                   ((fn [conf] (if (= 1 (:ssl conf))
                                 (merge conf {:ssl? true
                                              :ssl-context
                                              ssl-context})
                                 (merge conf {:ssl? false}))))
                   tcp/client)]
      (d/loop
        []
        (d/chain
          (gio/decode-stream @tcp protocol)
          (partial s/transform (get-message-parser @config))
          (partial s/transform @andi-transducer-stack)
          (fn [msg]
            (when-not (s/closed? msg) (d/recur)))))
      (on-connect @tcp)))

Arnaud Geiser 2022-10-31T18:22:31.595849Z

Hello! Are you sure it's related to your Aleph TCP client? We are doing much on Aleph side regarding TCP, It's rather trivial. [1] I don't know about the Netty defaults, so maybe you can use a bootstrap-transform to set SO_TIMEOUT [2] to a bigger value. [1] : https://github.com/exoscale/aleph/blob/master/src/aleph/netty.clj#L977-L984 [2] : https://netty.io/4.1/api/io/netty/channel/ChannelOption.html#SO_TIMEOUT

kkruit 2022-10-31T18:24:45.854569Z

thanks for the quick response! I'll look into that.

Arnaud Geiser 2022-10-31T18:25:25.900869Z

Otherwise, I know that @dergutemoritz is writing TCP servers with Aleph and might help you better than I can.

kkruit 2022-10-31T18:25:57.410429Z

And to your point I don't think it's aleph I'm pretty sure it's netty I just am not too familiar with it.

Arnaud Geiser 2022-10-31T18:25:58.652089Z

Is it possible it's related to a timeout on the server side also?

kkruit 2022-10-31T18:27:05.998909Z

No, I don't think so I've connected using generic java Socket before and it stays open so I don't think it's the server.

Arnaud Geiser 2022-10-31T18:28:38.406679Z

I'm more confortable with the HTTP part of it, but to have an idle-timeout behaviour, you need to explicitly define an IdleStateHandler [1] otherwise it will be no timeout at all. That's why I would expect the default Bootstrap to have no timeout at all. [1] : https://github.com/clj-commons/aleph/blob/master/src/aleph/http/core.clj#L633-L638

kkruit 2022-10-31T23:03:55.657269Z

I've mostly figured it out. I had a few issues. The biggest underlying issue is the server i'm connecting to allows for 32 bit messages on TLS so any message over 16709 bytes throws a SSLProtocolException. Thanks again for your help!

Arnaud Geiser 2022-11-01T06:33:51.223569Z

Great! You figured it by ourselves.Thanks for the feedback and do not hesitate if we can help.

dergutemoritz 2022-11-02T09:20:43.047399Z

Just to confirm: Yeah, there is no default idle timeout at all for TCP servers and clients.

👍 1
Arnaud Geiser 2022-11-02T09:21:50.736519Z

Thank you Moritz