I’m attempting to use a custom session cache module for the ssl application. I’ve got the following in config/config.exs
:
config :ssl,
session_cb: TlsServer.SessionCache
The module itself looks like this:
defmodule TlsServer.SessionCache do
@behaviour :ssl_session_cache_api
defdelegate init(options), to: :ssl_session_cache
defdelegate terminate(ref), to: :ssl_session_cache
defdelegate lookup(ref, key), to: :ssl_session_cache
defdelegate update(ref, key, session), to: :ssl_session_cache
defdelegate delete(ref, key), to: :ssl_session_cache
defdelegate foldl(fun, acc, ref), to: :ssl_session_cache
defdelegate select_session(ref, port), to: :ssl_session_cache
defdelegate size(ref), to: :ssl_session_cache
end
…yes, it just delegates everything at the moment.
But when I run it with PORT=15350 iex -S mix run --no-halt
, I get the following error:
17:19:01.821 [info] Application ssl exited: :ssl_app.start(:normal, []) returned an error: shutdown: failed to start child: :ssl_admin_sup
** (EXIT) shutdown: failed to start child: :ssl_manager
** (EXIT) an exception was raised:
** (UndefinedFunctionError) function TlsServer.SessionCache.init/1 is undefined (module TlsServer.SessionCache is not available)
TlsServer.SessionCache.init([role: :client])
(ssl 9.5.3) ssl_manager.erl:237: :ssl_manager.init/1
(stdlib 3.11.2) gen_server.erl:374: :gen_server.init_it/2
(stdlib 3.11.2) gen_server.erl:342: :gen_server.init_it/6
(stdlib 3.11.2) proc_lib.erl:249: :proc_lib.init_p_do_apply/3
Is there something I need to do differently to configure an Elixir module as a callback to an Erlang module? Or is there some problem with my module not being available at the correct time, somehow?
Do I have a problem that my application depends on ranch, which depends on ssl, which depends on a module from my application? That wouldn’t matter in Erlang, but does Elixir lazily-load my module or something?