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
Lets say I have map like this fetching from my database
%{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
Hi everyone!
I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
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
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? Ecto.Repo — Ecto v3.14.0 has exampl...
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
Good day to you all.
I have been struggling to get a query involving like and ilike to work.
Can anyone assist me on this, please?
pro...
New
Other popular topics
Hi!
In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir?
Searched the docs for ip address and the web, no good results.
Thanks!
New
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
Lets say I have map like this fetching from my database
%{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
I would like to know what is the best IDE for elixir development?
New
Hello!
Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something…
Haskell reminds me of Java, and e...
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









