Janardhan111

Janardhan111

(DBConnection.ConnectionError) ssl recv: closed (the connection was closed by the pool, possibly due to a timeout or because the pool has been terminated)

We have (DBConnection.ConnectionError) error in multiple places in our production only.

2025-09-03T16:13:51.0122410Z Request: POST /user/employee
2025-09-03T16:13:51.0122511Z ** (exit) an exception was raised:
2025-09-03T16:13:51.0122564Z     ** (DBConnection.ConnectionError) ssl recv: closed (the connection was closed by the pool, possibly due to a timeout or because the pool has been terminated)
2025-09-03T16:13:51.0122619Z         (ecto_sql 3.3.3) lib/ecto/adapters/sql.ex:612: Ecto.Adapters.SQL.raise_sql_call_error/1
2025-09-03T16:13:51.0122667Z         (ecto 3.3.4) lib/ecto/repo/schema.ex:655: Ecto.Repo.Schema.apply/4
2025-09-03T16:13:51.0122737Z         (ecto 3.3.4) lib/ecto/repo/schema.ex:263: anonymous fn/15 in Ecto.Repo.Schema.do_insert/4
2025-09-03T16:13:51.0122790Z         (my_app 4.0.0) lib/my_app/pension/workflow.ex:39: MyApp.Pension.Workflow.create_pension/2
2025-09-03T16:13:51.0122840Z         (ecto_sql 3.3.3) lib/ecto/adapters/sql.ex:886: anonymous fn/3 in Ecto.Adapters.SQL.checkout_or_transaction/4
2025-09-03T16:13:51.0122891Z         (db_connection 2.2.1) lib/db_connection.ex:1427: DBConnection.run_transaction/4
2025-09-03T16:13:51.0122966Z         (my_app 4.0.0) lib/my_app/controllers/employee_controller.ex:328: MyAppWeb.EmployeeController.create/3
2025-09-03T16:13:51.0123016Z         (my_app 4.0.0) lib/my_app/controllers/employee_controller.ex:1: MyAppWeb.EmployeeController.action/2

below is the function MyApp.Pension.Workflow.create_pension/2

 def create_pension(changeset, current_user) do
    # here we are inserting a new record into pensions table
    case Repo.insert(changeset) 
	.......

the below is the another function the error is repeating


2025-09-03T15:16:43.7459272Z 15:16:43.744 [error] Task #PID<0.5423.30> started from #PID<0.5443.30> terminating
2025-09-03T15:16:43.7459738Z ** (DBConnection.ConnectionError) ssl recv: closed (the connection was closed by the pool, possibly due to a timeout or because the pool has been terminated)
2025-09-03T15:16:43.7459826Z     (ecto_sql 3.3.3) lib/ecto/adapters/sql.ex:612: Ecto.Adapters.SQL.raise_sql_call_error/1
2025-09-03T15:16:43.7459892Z     (ecto_sql 3.3.3) lib/ecto/adapters/sql.ex:545: Ecto.Adapters.SQL.execute/5
2025-09-03T15:16:43.7459998Z     (my_app 4.0.0) lib/my_app_web/plugs/user_auth_plug.ex:209: MyAppWeb.UserAuthPlug.update_last_seen!/2
2025-09-03T15:16:43.7460059Z     (elixir 1.13.4) lib/task/supervised.ex:89: Task.Supervised.invoke_mfa/2
2025-09-03T15:16:43.7460121Z     (elixir 1.13.4) lib/task/supervised.ex:34: Task.Supervised.reply/4
2025-09-03T15:16:43.7460179Z     (stdlib 3.14.2.2) proc_lib.erl:226: :proc_lib.init_p_do_apply/3
2025-09-03T15:16:43.7460262Z Function: #Function<0.37496757/0 in MyAppWeb.UserAuthPlug.put_current/3>
2025-09-03T15:16:43.7460334Z     Args: []

below is the MyAppWeb.UserAuthPlug.update_last_seen! method

  def update_last_seen!(%{id: id}, repo) when not is_nil(id) do
    "users"
    |> from
    |> where(id: ^id)
    |> update(set: [last_seen_at: ^NaiveDateTime.utc_now()])
    |> repo.update_all([])

    :ok
  end

We tried increasing the database pool size from 36 to 50. still it didn’t show any improvement. Can someone please help me here.

First Post!

arcanemachine

arcanemachine

(Just offering my input until somebody competent comes along…)

Have you tried increasing the :queue_target in your repo? Maybe that will resolve the issue if the query is timing out.

Here is a list of hard-to-find options that may be relevant (these would go in your repo config):

Last Post!

Janardhan111

Janardhan111

I could see the update_last_seen/2 function is in waiting state at the database and the reason is LOCK. Can this lock occur for 15000ms ?

Any suggestion on how to identify which other query is locking the row? How to resolve it ?

Where Next?

Popular in Questions Top

vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
joaquinalcerro
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
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
nsuchy
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
fireproofsocks
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
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
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New

Other popular topics Top

Qqwy
Update: How to use the Blogs &amp; Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3271 130286 1222
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
lanycrost
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
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
bsollish-terakeet
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
AngeloChecked
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

We're in Beta

About us Mission Statement