Fork me on GitHub
#aleph
<
2022-10-31
>
kkruit18:10:29

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

kkruit18:10:45

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.

kkruit18:10:57

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?

kkruit18:10:05

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] : https://github.com/clj-commons/aleph/blob/master/src/aleph/http/core.clj#L633-L638

kkruit23:10:55

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.

dergutemoritz09:11:43

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