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.
Popular in Questions
can someone please explain to me how Enum.reduce works with maps
New
Credo is smart enough to check for (something like) this:
assert length(the_list) == 0
with this response:
Checking if an enum is empt...
New
Hi, I’m using Ubuntu 18.04 and after updating to OTP-24.0 yesterday i have this warning when I run “mix local.hex”:
14:57:30.512 [warn] ...
New
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible.
total = 10
while total != 0
...
New
I have a list say
x = ["23gh", "56kh", "97mh"]
I would like to pass each element to Val in each iteration.
Say, in iteration 1 -------...
New
I tried installing
elixir 1.11.2
erlang 23.3.4
via asdf in my zsh shell. Enabled the versions locally and globally.
When I list them ...
New
To simplify some tasks at work, I wrote and published this package yesterday. It’s a simple macro that enables Access behaviour on struct...
New
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
I am trying to run a deploy with docker and I successfully runned with this command:
docker build -t romenigld/blog-prod .
but when I t...
New
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
Other popular topics
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
New
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1]
15:22:35.803 [error] gen_event {lager_file_backend...
New
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
In the Dialyzer docs ( http://erlang.org/doc/man/dialyzer.html#requesting-or-suppressing-warnings-in-source-files ), there is a way to tu...
New
I have followed this StackOverflow post to install the specific version of Erlang.
And When I am running mix ecto.setup then getting fol...
New
I have an umbrella app.
Some of the apps inside depend on other apps in the umbrella, unsurprisingly.
I'm writing a test for one of t...
New
The Elixir Typespec docs show the following syntax for keyword lists in typespecs:
# ...
| [key: type] # keyword lis...
New
Hello everybody,
usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
Original source of discussion: This topic on the Pragmatic Programmers' Functional Web Development with Elixir, OTP, and Phoenix forum.
...
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







