<div dir="ltr">Hi.<div><br></div><div>Seems that I met rather rare situation when send_timeout doesn't help from memory leak.</div><div><br></div><div><br></div><div>I have an architecture, when central process send messages with big binary blobs to subscribed processes via plain !</div><div><br></div><div>Each process takes messages and tries to write to socket which is configured with {send_timeout, 10000}.  If socket replies with {error, timeout} then process is closed and no more messages are received.</div><div><br></div><div>This architecture can work only if gen_tcp:send will 100% return after 10, maybe 15 or at least 60 seconds.</div><div><br></div><div><br></div><div><br></div><div>After customer has masterly configured bonding on 4 ethernet ports and cut 2 of 4 cables, we've got rare situation with 50% of packet loss.</div><div><br></div><div>It lead to very interesting situation when plenty of processes are locked in prim_inet send for many minutes.</div><div><br></div><div>gen_tcp:send doesn't allow to pass nosuspend option to port_command and thus it is impossible to send data to socket with real timeout.  If tcp socket is blocked, erlang:port_command will be blocked for a veeeryy long time.</div><div><br></div><div><br></div><div>I had to refuse from gen_tcp to port_command and enable add missing timeout there:</div><div><br></div><div><div>send(Socket, Data) -></div><div>  try erlang:port_command(Socket, Data, [nosuspend]) of</div><div>    false -></div><div>      {error, busy};</div><div>    true -></div><div>      receive</div><div>        {inet_reply, Socket, Status} -> Status</div><div>      after</div><div>        20000 -> {error, timeout}</div><div>      end</div><div>  catch</div><div>    error:Error -></div><div>      {error, Error}</div><div>  end.</div></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div>Another way to handle it is to launch a process that will scan erlang:processes() and check their message_queue_len. Very "elegant" and "good designed" solution, but it will work.</div><div><br></div><div><br></div><div><br></div><div>What is the proper way to handle such situation?  And yes, I cannot use gen_server:call from central process to clients, because I need it to scale to 2000-3000 secondary processes.</div><div><br></div></div>