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
In Ruby, I can go:
User.find_by(email: "foobar@email.com").update(email: "hello@email.com")
How can I do something similar in Elixir?
...
New
Hello everyone,
I try to use an Javascript Event Handler in my root.html.leex file.
Therefore I created a function in the app.js file: ...
New
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
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
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this:
...
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
I have a User schema with a :from_id field set to type :string:
defmodule TweetBot.Repo.Migrations.CreateUsers do
use Ecto.Migration
...
New
Hi!
Currently I want to submit a form by pressing the Enter key. However, since my input field is of type “textarea” this is just adds a...
New
Other popular topics
If I have a post route which an argument:
post /my_post_route/:my_param1, MyController.my_post_handler
How would get the post params ...
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
Anybody knows a comprehensive comparison of Django and Phoenix, thanks for the help.
Where are they similar?
Where do they differ the m...
New
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
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
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
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar.
I p...
New
I would like to know what is the best IDE for elixir development?
New
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
New
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New








