From cd41f43e85ac11e77174f4a3524da9b512ad9832 Mon Sep 17 00:00:00 2001 From: Ryan Winchester Date: Mon, 16 Dec 2019 18:25:47 -0800 Subject: [PATCH] Handle ssl listen error on unsolicited server --- lib/grizzly/unsolicited_server.ex | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/grizzly/unsolicited_server.ex b/lib/grizzly/unsolicited_server.ex index 70f809c7..a86a0814 100644 --- a/lib/grizzly/unsolicited_server.ex +++ b/lib/grizzly/unsolicited_server.ex @@ -26,7 +26,7 @@ defmodule Grizzly.UnsolicitedServer do :listen, %State{config: %Config{ip_address: ip_address, ip_version: ip_version}} = state ) do - case :ssl.listen(41230, opts(ip_address, ip_version)) do + case ssl_listen(ip_address, ip_version) do {:ok, listensocket} -> _ = Logger.info("[GRIZZLY]: unsolicited server waiting for connections") start_accepting_sockets(listensocket) @@ -43,6 +43,14 @@ defmodule Grizzly.UnsolicitedServer do end end + def ssl_listen(ip_address, ip_version) do + try do + :ssl.listen(41230, opts(ip_address, ip_version)) + rescue + error -> error + end + end + def start_accepting_sockets(listensocket) do Enum.each(1..10, fn _ -> SocketSupervisor.start_socket(listensocket) end) end