Skip to content

Instantly share code, notes, and snippets.

@vinoski
Created November 28, 2012 18:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vinoski/4163038 to your computer and use it in GitHub Desktop.
Save vinoski/4163038 to your computer and use it in GitHub Desktop.
Erlang R15B03 SSL accept timeout bug example
-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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment