Laetitia
Task + DbTransaction DbConnection error
Hi guys,
I would like to know if anybody could help me.
I have a genserver that calls a TaskSupervisor to start tasks like this:
task =
Task.Supervisor.async_nolink(
UiccProvisioningsSupervisor,
fn -> Toto.bar() end
)
Process.send_after(self(), {:kill, task}, state.task_timeout)
and a handle_info like this:
def handle_info({:kill, task}, %{tasks: tasks} = state) do
if tasks[task.ref] do
Task.shutdown(task, :brutal_kill)
Toto.call_to_db()
{:noreply, %{state | tasks: Map.delete(tasks, task.ref)}}
else
{:noreply, state}
end
The toto.foo contains a transaction like this:
def foo(params) do
Repo.transaction(fn ->
ota_request = Repo.insert!(%Foo{} |> Foo.create_changeset(params))
Process.sleep(150)
end)
end
In this case , I got in the terminate callback of the Genserver:
scheduler terminated: {{:shutdown,
%DBConnection.ConnectionError{
message: "client #PID<0.698.0> exited",
reason: :error,
severity: :error
}},
{DBConnection.Holder, :checkout,
[
#PID<0.682.0>,
[
log: #Function<13.1473765/1 in Ecto.Adapters.SQL.with_log/3>,
source: "uicc_provisionings",
cast_params: [nil, nil, ~N[2023-06-22 11:12:24], "icc_id_3529"],
repo: SimManager.Repo,
timeout: 15000,
pool: DBConnection.Ownership,
pool_size: 10
]
]}}
I found that the task is the exited client. And the problem disappears when I remove the transaction.
First Post!
al2o3cr
Hard to say 100% without real code, but my suspicion is that the Task ends up sharing a database connection with the GenServer, then brutal_killing the Task leaves the connection in an unusable state.
0
Popular in Questions
I would like to know what is the best IDE for elixir development?
New
lets say i have a sample like
a = 20; b = 10;
if (a > b) do
{:ok, "a"}
end
if (a < b) do
{:ok, b}
end
if (a == b) do
{:ok, "equa...
New
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
What is the idiomatic way of matching for not nil in Elixir?
E.g.,
First way:
defp halt_if_not_signed_in(conn, signed_in_account) when...
New
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
Other popular topics
Hi,
I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
Hi there,
I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
I would like to know what is the best IDE for elixir development?
New
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!)
This post collects co...
New
What learn first? Rust or Elixir
Hi Elixir community!
I’m here because i want learn a new language. I’m a junior developer and mainly i ...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex









