Created
November 28, 2012 18:22
-
-
Save vinoski/4163038 to your computer and use it in GitHub Desktop.
Erlang R15B03 SSL accept timeout bug example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-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