public
Created

Erlang R15B03 SSL accept timeout bug example

  • Download Gist
ssl_accept_bug.erl
Erlang
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
-module(ssl_accept_bug).
-export([start/0]).
 
-define(PORT, 9999).
 
start() ->
ssl:start(),
%% You can get the Yaws cert and key files here:
%% https://github.com/klacke/yaws/blob/master/ssl/yaws-cert.pem
%% https://github.com/klacke/yaws/blob/master/ssl/yaws-key.pem
%% Or just change the code to use some other cert and key files.
{ok,LS} = ssl:listen(?PORT,
[{certfile, "yaws-cert.pem"},
{keyfile, "yaws-key.pem"},
{reuseaddr, true}]),
try
ok = spawn_accept(LS),
ok = client()
catch
C:R ->
{C,R}
after
ssl:close(LS)
end.
 
spawn_accept(LS) ->
spawn(fun() ->
{ok,TS} = ssl:transport_accept(LS),
{error,timeout} = ssl:ssl_accept(TS, 5000)
end),
ok.
 
client() ->
{ok,S} = gen_tcp:connect("localhost", ?PORT, [binary, {active,true}]),
%% The connection should timeout with a tcp_closed message after 5 seconds
%% since we never complete the SSL accept
receive
{tcp_closed,S} ->
ok
after
6000 -> fail
end.

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.