Hej Peter, velkommen til! 
Not sure I completely understand the use case… I assume mnesia is used as a cache? eg. you gotta maintain single source of truth?
that said I would look at using Ecto.Multi https://hexdocs.pm/ecto/Ecto.Multi.html
if you want to do the optimistic path (which might “lie”) do the mnesia first in the “multi” then the db stuff - if db fails you can cleanup whatever made it into mnesia.
if you want to always be “truthful” do the db stuff first then the mnesia in the “multi”…
this ensures correct data at all times… so definitely take a look at implementing that…
though above should be implemented for data guarentees, it’s also relevant to look at the root cause - a (client/network) dropped request killing (underlying) processes, I’ve seen this happen, so I know it can happen…
how long does the request take and the data handling?
most likely look at protocol_options https://hexdocs.pm/plug_cowboy/Plug.Cowboy.html that leads to https://ninenines.eu/docs/en/cowboy/2.5/manual/cowboy_http/ - see this one for example on config’ing idle_timeout https://github.com/phoenixframework/phoenix/issues/3190
my best guess would be the shutdown_timeout - eg your data processing takes 6secs or more (due to queues or what not) and a request and dropped connection kills it after 5 secs
if you want to replicate locally I think something like this: (untested)
def create_data(conn, _params) do
task_time = 20_000
task = Task.async(fn -> :timer.sleep(task_time);IO.inspect("task done");"done" end)
data = Task.await(task)
IO.inspect("got data")
json(conn, %{data: data})
end
if you hit that controller and then kill browser window the linked task.async should be killed after 5secs if I understand correctly, and you will not see “task done” in iex… might be totally wrong though - wouldn’t be the first time…
Edit: actually cowboy might even kill a “dirty” (eg. side effect: mnesia + db transaction) multi, so maybe skip that part and jump straight to replicating locally and looking at cowboy options…