Skip to content

Commit

Permalink
Fix race condition in ensure_table_present
Browse files Browse the repository at this point in the history
  • Loading branch information
arcusfelis committed Jul 30, 2024
1 parent 67f424a commit 755e39e
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/escalus_fresh.erl
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,23 @@ do_delete_users(Conf) ->


ensure_table_present(T) ->
Parent = self(),
StartRef = make_ref(),
RunDB = fun() -> ets:new(T, [named_table, public]),
Parent ! {started, StartRef},
receive bye -> ok end end,
case ets:info(T) of
undefined ->
P = spawn(RunDB),
erlang:register(T, P);
{Pid, Mon} = spawn_monitor(RunDB),
receive
{started, StartRef} ->
erlang:register(T, Pid),
erlang:demonitor(Mon);
{'DOWN', Mon, process, Pid, _Reason} ->
ok
after 5000 ->
error(failed_to_start_fresh_table)
end;
_nasty_table_is_there_well_run_with_it -> ok
end.

Expand Down

0 comments on commit 755e39e

Please sign in to comment.