wallaby
wallaby copied to clipboard
Use Wallaby in production
Hey, I'm trying to use Wallaby in production since I'm using it for browser automation and scraping. I have chromedriver and chrome set up in a Dockerfile and fixed those errors. But now I'm stuck at this:
2025-04-02T21:16:36.242 app[68306d3a13de28] arn [info] 21:16:36.240 [notice] Application wallaby exited: Wallaby.start(:normal, []) returned an error: shutdown: failed to start child: Wallaby.SessionStore
2025-04-02T21:16:36.242 app[68306d3a13de28] arn [info] ** (EXIT) an exception was raised:
2025-04-02T21:16:36.242 app[68306d3a13de28] arn [info] ** (UndefinedFunctionError) function ExUnit.after_suite/1 is undefined (module ExUnit is not available). Make sure the module name is correct and has been specified in full (or that an alias has been defined)
2025-04-02T21:16:36.242 app[68306d3a13de28] arn [info] ExUnit.after_suite(#Function<0.26441557/1 in Wallaby.SessionStore.init/1>)
2025-04-02T21:16:36.242 app[68306d3a13de28] arn [info] (wallaby 0.30.10) lib/wallaby/session_store.ex:41: Wallaby.SessionStore.init/1
2025-04-02T21:16:36.242 app[68306d3a13de28] arn [info] (stdlib 6.2) gen_server.erl:2229: :gen_server.init_it/2
2025-04-02T21:16:36.242 app[68306d3a13de28] arn [info] (stdlib 6.2) gen_server.erl:2184: :gen_server.init_it/6
2025-04-02T21:16:36.242 app[68306d3a13de28] arn [info] (stdlib 6.2) proc_lib.erl:329: :proc_lib.init_p_do_apply/3
2025-04-02T21:16:37.772 app[68306d3a13de28] arn [info] Kernel pid terminated (application_controller) ("{application_start_failure,wallaby,{{shutdown,{failed_to_start_child,'Elixir.Wallaby.SessionStore',{undef,[{'Elixir.ExUnit',after_suite,[#Fun<Elixir.Wallaby.SessionStore.0.26441557>],[]},{'Elixir.Wallaby.SessionStore',init,1,[{file,\"lib/wallaby/session_store.ex\"},{line,41}]},{gen_server,init_it,2,[{file,\"gen_server.erl\"},{line,2229}]},{gen_server,init_it,6,[{file,\"gen_server.erl\"},{line,2184}]},{proc_lib,init_p_do_apply,3,[{file,\"proc_lib.erl\"},{line,329}]}]}}},{'Elixir.Wallaby',start,[normal,[]]}}}")
2025-04-02T21:16:37.980 app[68306d3a13de28] arn [info] Crash dump is being written to: erl_crash.dump...done
2025-04-02T21:16:38.679 app[68306d3a13de28] arn [info] INFO Main child exited normally with code: 1
Is there a way to use Wallaby in production? Thanks.
@svelterust I have been using this patch, and it works well so far
diff --git a/lib/wallaby/session_store.ex b/lib/wallaby/session_store.ex
index f666b3fced...16807550ef 100644
--- a/lib/wallaby/session_store.ex
+++ b/lib/wallaby/session_store.ex
@@ -36,17 +36,23 @@
Process.flag(:trap_exit, true)
tid = :ets.new(name, opts)
- Application.ensure_all_started(:ex_unit)
+ mix_env = System.get_env("MIX_ENV")
- ExUnit.after_suite(fn _ ->
- try do
- :ets.tab2list(tid)
- |> Enum.each(&delete_sessions/1)
- rescue
- _ -> nil
- end
- end)
+ if mix_env == "test" do
+ Application.ensure_all_started(:ex_unit)
+ ExUnit.after_suite(
+ fn _ ->
+ try do
+ :ets.tab2list(tid)
+ |> Enum.each(&delete_sessions/1)
+
+ rescue
+ _ -> nil
+ end
+ end)
+ end
+
{:ok, %{ets_table: tid}}
end
Nice, I did similar except I added check if :ex_unit is loaded.