Laetitia

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

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.

Where Next?

Popular in Questions Top

sergio
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
marius95
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
_russellb
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
lastday4you
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
ycv005
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
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
aalberti333
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
fayddelight
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
chensan
I have a User schema with a :from_id field set to type :string: defmodule TweetBot.Repo.Migrations.CreateUsers do use Ecto.Migration ...
New
svb
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 Top

Darmani72
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
9mm
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
Nvim
Anybody knows a comprehensive comparison of Django and Phoenix, thanks for the help. Where are they similar? Where do they differ the m...
New
chrismccord
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
New
dokuzbir
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
fayddelight
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
dblack
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
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
AstonJ
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
New
jononomo
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

We're in Beta

About us Mission Statement