I am puzzled at some random errors we are getting in staging. This is a new B2B website project with the back-end HTTP API using the Elixir / Ecto / Phoenix stack. We are getting close to release date and this is worrying us to no-end.
All queries work fine and we have gotten no errors whatsoever during testing and / or on staging website.
The problem seems to only be during actual insertion of new data via Ecto.multi.
I am personally pretty new to Elixir itself so I am at a bit of a loss at where to look. Here is an example transaction:
multi =
Multi.new
|> Multi.insert(:salesorder, salesorder_changeset) # Create a sales order operation
|> Multi.run(:address, fn %{salesorder: salesorder} -> # Create address changeset
address_changeset =
%Salesorderaddress{salesorderid: salesorder.id}
|> Salesorderddress.changeset(soldto)
Repo.insert(address_changeset)
end )
|> (more operations)
This sometimes work or not depending on the server mood it seems…
Here is the error we are getting in the console:
[error] #PID<0.453.0> running CmiserverWeb.Endpoint (cowboy_protocol) terminated
Server: localhost:4000 (http)
Request: POST /api/v1/auth/checkout/submitorder
** (exit) an exception was raised:
** (Mssqlex.Error) connection_closed
(db_connection) lib/db_connection.ex:802: DBConnection.transaction/3
(ecto) lib/ecto/repo/queryable.ex:21: Ecto.Repo.Queryable.transaction/4
(cmiserver) lib/cmiserver/orders.ex:578: Cmiserver.Orders.submit_multi/4
(cmiserver) lib/cmiserver_web/controllers/auth/checkout/checkout_submitorder.ex:22: CmiserverWeb.Auth.Checkout.SubmitOrderController.index/2
(cmiserver) lib/cmiserver_web/controllers/auth/checkout/checkout_submitorder.ex:1: CmiserverWeb.Auth.Checkout.SubmitOrderController.action/2
(cmiserver) lib/cmiserver_web/controllers/auth/checkout/checkout_submitorder.ex:1: CmiserverWeb.Auth.Checkout.SubmitOrderController.phoenix_controller_pipeline/2
I looked at the code of both the Ecto MS SQL Adapter (mssql-ecto) and its MS SQL driver (mssqlex) and from what I could figure out (definitely beyond my skills Elixir-wise) the error seems to come from Db_connection.
Due to our use of MSSQL (not a choice!) as the database server we are currently limited in dependencies to these versions:
{:ecto, "~> 2.2.0"},
{:mssql_ecto, "~> 1.2.0"},
{:mssqlex, "~> 1.1.0"}
So far we have tried changing the :pool_size and the :timeout on the Repo without success either.
I am completely at a loss as where to look next. I wish we could go with Postgrex but changing the back-end of the in-house accounting system (C#, EF, etc) would be also a huge project.
Any help would be much appreciated.
Thank you in advance