smedegaard

smedegaard

Ranch connection silently becomming inactive?

I’ve got an app that connects to a number of tcp ports using :ranch_tcp.connect/3

I connect in passive mode and then switch to active once I get {:ok, socket}.
When I get the socket I execute a Telemetry message:

 case :ranch_tcp.connect(...) do
      {:ok, socket} ->
          ...
          :telemetry.execute(
            [:some, :key],
            %{active: 1}
          )
          ...

I call :telemetry.execute in each of handle_info({:tcp_closed, _socket}, _state ) and handle_info({:tcp_error, _socket}, _state ) where I set the active key to 0.

One of the systems I connect to is a back-up system that is only used if we need a fail-over for some reason. Thus there is only very infrequently traffic from that ip/port. When such a fail-over occurred I did not get any messages form the back-up connection.
Telemetry had not executed an active: 0 message.

So my question is:
Is there a way that a tcp connection in Ranch/gen_tcp can become inactive without being caught by {tcp_error, _} or {tcp_closed, _}?

Marked As Solved

voltone

voltone

Just a wild stab in the dark, but could it be there is some stateful network element (NAT, firewall) on the TCP path, which dropped the connection for inactivity? In that case the connection may still have been in active mode in the BEAM, but the packets simply never made it through the network. I’ve been bitten by this.

If you can’t be sure the network path fully transparent, keeping idle TCP connections open may require some keep alive, either at the kernel level (see keepalive in gen_tcp options) or the application level (periodically send a newline, or something else that does not cause the other end to choke).

Also Liked

smedegaard

smedegaard

For posterity:

I searched the logs and indeed found some suspicious TCP FIN messages. Hopefully someone in the future will see this and save the selves some head scratching because of silent tcp sockets.

Where Next?

Popular in Questions Top

lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New
mathew4509
I have a list say x = ["23gh", "56kh", "97mh"] I would like to pass each element to Val in each iteration. Say, in iteration 1 -------...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
Exadra37
Sometimes I want to check if the input into a function is not a blank string. My first approach: defmodule Example do def do_stuff(s...
New
Codball
Mix format works fine if run from the cmd. I’ve followed this to facilitate the implementation into VSC which involves downloading an ext...
New
Mooodi
Given a string, how can I get access to its character by index? Enum.at("my_string", 2) doesn't work. Or rather, not char, but a substr...
New

Other popular topics Top

shahryarjb
Hello, I get Persian date from my client and convert it to normal calendar like this: def jalali_string_to_miladi_english_number(persi...
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 49522 488
New
Jim
As a follow up to my earlier question: I have the code compiling and running but not getting a successful login from the rest server. ...
New
chrismccord
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers' Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New

We're in Beta

About us Mission Statement