Connection Error when exists concurrency inside a transaction.
williamff11 opened this issue · comments
Hello! I have a Task.async_stream() called inside of a Multi.run. When this Task.async_stream() is called, a error is hurled:
** (DBConnection.ConnectionError) could not checkout the connection owned by #PID<0.897.0>. When using the sandbox, connections are shared, so this may imply another process is using a connection. Reason: connection not available and request was dropped from queue after 931ms. You can configure how long requests wait in the queue using :queue_target and :queue_interval. See DBConnection.start_link/2 for more information.
But, when I call this Task.async_stream() outside Multi.run, the code runs successfully.
What is your Elixir and db_connection versions?
Elixir: 1.10.4
db_connection: 2.3.1
Ok, so the reason this is happening is because the sandbox is a single connection shared by all of your task async streams. So if you have a lot of task async stream, they will fight over the same connection and eventually they will time out checking it out. You can increase the queue_target and queue_interval for your test environment in your repo configuration OR reduce the task async stream concurrency during test (or both).