aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorLukas Larsson <[email protected]>2011-12-07 14:47:40 +0100
committerLukas Larsson <[email protected]>2011-12-08 15:13:31 +0100
commit4181dc36580a0ec7476aeed389948976a89c755d (patch)
tree5bd97dca565eaf86cbf3b0a2e36e268d4ef3e469 /lib
parent1137c0a08b25ab5e38286260f0b7c51ba015afbb (diff)
downloadotp-4181dc36580a0ec7476aeed389948976a89c755d.tar.gz
otp-4181dc36580a0ec7476aeed389948976a89c755d.tar.bz2
otp-4181dc36580a0ec7476aeed389948976a89c755d.zip
Fix cleanup when sendfile process crashes
When sendfile crashes during a send there should be no error_logger printouts about stolen fds.
Diffstat (limited to 'lib')
-rw-r--r--lib/kernel/test/sendfile_SUITE.erl41
1 files changed, 41 insertions, 0 deletions
diff --git a/lib/kernel/test/sendfile_SUITE.erl b/lib/kernel/test/sendfile_SUITE.erl
index 483290b91a..6d0848ee05 100644
--- a/lib/kernel/test/sendfile_SUITE.erl
+++ b/lib/kernel/test/sendfile_SUITE.erl
@@ -34,6 +34,7 @@ all() ->
,t_sendfile_sendduring
,t_sendfile_recvduring
,t_sendfile_closeduring
+ ,t_sendfile_crashduring
].
init_per_suite(Config) ->
@@ -241,6 +242,35 @@ t_sendfile_closeduring(Config) ->
ok = sendfile_send({127,0,0,1}, Send, 0).
+t_sendfile_crashduring(Config) ->
+ Filename = proplists:get_value(big_file, Config),
+
+ error_logger:add_report_handler(?MODULE,[self()]),
+
+ Send = fun(Sock) ->
+ spawn_link(fun() ->
+ timer:sleep(50),
+ exit(die)
+ end),
+ {error, closed} = file:sendfile(Filename, Sock),
+ -1
+ end,
+ process_flag(trap_exit,true),
+ spawn_link(fun() ->
+ ok = sendfile_send({127,0,0,1}, Send, 0)
+ end),
+ receive
+ {stolen,Reason} ->
+ process_flag(trap_exit,false),
+ ct:fail(Reason)
+ after 200 ->
+ receive
+ {'EXIT',_,Reason} ->
+ process_flag(trap_exit,false),
+ die = Reason
+ end
+ end.
+
%% Generic sendfile server code
sendfile_send(Send) ->
sendfile_send({127,0,0,1},Send).
@@ -312,3 +342,14 @@ sendfile_file_info(File) ->
{ok, #file_info{size = Size}} = file:read_file_info(File),
{ok, Data} = file:read_file(File),
{Size, Data}.
+
+
+%% Error handler
+
+init([Proc]) -> {ok,Proc}.
+
+handle_event({error,noproc,{emulator,Format,Args}}, Proc) ->
+ Proc ! {stolen,lists:flatten(io_lib:format(Format,Args))},
+ {ok,Proc};
+handle_event(_, Proc) ->
+ {ok,Proc}.