Fork me on GitHub

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
                                 (merge conf {:ssl? false}))))
          (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 Geiser18:10:31

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] : [2] :


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

Arnaud Geiser18:10:25

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


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 Geiser18:10:58

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


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 Geiser18:10:38

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] :


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 Geiser06:11:51

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


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

👍 1
Arnaud Geiser09:11:50

Thank you Moritz