{:tcp_closed, pid} GenServer Error

I’ve a GenServer that polls a table every minute, compares the table records to another table and then fire an api call for each record. My GenServer crashes prior when receiving a message to start the polling after the initial poll. It was reporting of undefined function clause for handle_info. I added a general handle_info function - strangely I’m receiving {:tcp_closed, #Port<0.80>}, I’m not sure where this message is being sent from, in a dev environment.

Are you using HTTPoison / Hackney per chance? Hackney likes to leak {:tcp_closed, port} messages periodically. Your best bet is to just define this handle info clause:

def handle_info({:tcp_closed, _}, state), do: {:noreply, state}
3 Likes

The api called is via Mojito, though I also use hackney(leaves header casing intact but Mojito converts to lower case) for other api calls. The GenServer only uses Mojito in this case, is there a way to check with process is sending this. I’ve not had an experience with Mojito sending this. Thanks a lot sir.

You’ve likely already heard this somewhere else, but any backend that is sensitive to case in its request headers is not HTTP-spec-compliant, and should be corrected there if you have any control of it.

2 Likes