<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">Hi,<div class=""><br class=""></div><div class="">I’m seeing a potential issue with file:sendfile if the client shuts down the connection.  My setup is a cowboy server with a simple cowboy_static endpoint, and a rate-limited curl as the client - if I start the curl download and then ctrl-c curl before it completes, cowboy sits hung inside the call to sendfile.  </div><div class=""><br class=""></div><div class="">I inspected the cowboy process as follows:</div><div class=""><br class=""></div><div class=""><div class=""><font face="Courier New" class="">(<a href="mailto:file_encoder@127.0.0.1" class="">file_encoder@127.0.0.1</a>)83> P = processes().</font></div><div class=""><font face="Courier New" class="">[<0.0.0>,<0.1.0>,<0.2.0>,<0.3.0>,<0.4.0>,<0.5.0>,<0.8.0>,</font></div><div class=""><font face="Courier New" class=""> <0.40.0>,<0.42.0>,<0.44.0>,<0.45.0>,<0.47.0>,<0.48.0>,</font></div><div class=""><font face="Courier New" class=""> <0.50.0>,<0.51.0>,<0.52.0>,<0.53.0>,<0.54.0>,<0.55.0>,</font></div><div class=""><font face="Courier New" class=""> <0.56.0>,<0.57.0>,<0.58.0>,<0.59.0>,<0.60.0>,<0.61.0>,</font></div><div class=""><font face="Courier New" class=""> <0.62.0>,<0.63.0>,<0.64.0>,<0.65.0>|…]</font></div><div class=""><font face="Courier New" class=""><br class=""></font></div><div class=""><font face="Courier New" class="">%% Run curl and ctrl-c in a separate window…</font></div><div class=""><font face="Courier New" class=""><br class=""></font></div><div class=""><font face="Courier New" class="">(<a href="mailto:file_encoder@127.0.0.1" class="">file_encoder@127.0.0.1</a>)84> erlang:process_info(hd(processes() -- P), [current_function, messages]).</font></div><div class=""><font face="Courier New" class="">[{current_function,{prim_inet,sendfile_1,4}},</font></div><div class=""><font face="Courier New" class=""> {messages,[{'EXIT',<0.1798.0>,normal},</font></div><div class=""><font face="Courier New" class="">            {tcp_closed,#Port<0.266>},</font></div><div class=""><font face="Courier New" class="">            {inet_reply,#Port<0.266>,{error,closed}}]}]</font></div></div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">This process looks doomed to live forever - it is stuck in prim_inet:sendfile_1 on the following receive:</div><div class=""><div class=""><br class=""></div><div class=""><font face="Courier New" class="">      receive</font></div><div class=""><font face="Courier New" class="">        {sendfile, S, {ok, SentLow, SentHigh}} -></font></div><div class=""><font face="Courier New" class="">          {ok, SentLow bor (SentHigh bsl 32)};</font></div><div class=""><font face="Courier New" class="">        {sendfile, S, {error, Reason}} -></font></div><div class=""><font face="Courier New" class="">          {error, Reason};</font></div><div class=""><font face="Courier New" class="">        {'EXIT', S, _Reason} -></font></div><div class=""><font face="Courier New" class="">          {error, closed}</font></div><div class=""><font face="Courier New" class="">      end</font></div></div><div class=""><br class=""></div><div class="">The port that it had opened, 0.266, has closed so there will never be an exit message:</div><div class=""><br class=""></div><div class=""><div class=""><font face="Courier New" class="">(<a href="mailto:file_encoder@127.0.0.1" class="">file_encoder@127.0.0.1</a>)89> erlang:ports().</font></div><div class=""><font face="Courier New" class="">[#Port<0.0>,#Port<0.2>,#Port<0.4>,#Port<0.5>,#Port<0.6>,</font></div><div class=""><font face="Courier New" class=""> #Port<0.8>,#Port<0.10>,#Port<0.11>,#Port<0.12>,#Port<0.13>,</font></div><div class=""><font face="Courier New" class=""> #Port<0.14>,#Port<0.15>,#Port<0.16>,#Port<0.254>,</font></div><div class=""><font face="Courier New" class=""> #Port<0.255>,#Port<0.256>,#Port<0.257>,#Port<0.258>,</font></div><div class=""><font face="Courier New" class=""> #Port<0.259>,#Port<0.260>,#Port<0.261>,#Port<0.262>,</font></div><div class=""><font face="Courier New" class=""> #Port<0.263>,#Port<0.264>]</font></div></div><div class=""><br class=""></div><div class="">I’m guessing the process wasn’t linked with the port, or it would have received the exit message and all would have been well.  Unsure if this is a cowboy or prim_inet bug, or indeed if I’ve done something wrong.  Any ideas?</div><div class=""><br class=""></div><div class="">Cheers,</div><div class=""><br class=""></div><div class="">Steve</div><div class=""><br class=""></div><div class=""><br class=""></div></body></html>