Closed gaynetdinov closed 2 years ago
Hello @gaynetdinov. That is a great catch. Do you have ideas on how we can solve that? I don't think there is a way in Ecto to reuse connection checked out for a process in it's child :(.
Maybe the simplest thing we can do is to add docs to run_async
on transaction isolation when used with Ecto.Repo.transaction.
This is the most comprehensive explanation regarding this topic I found from @fishcakez https://elixirforum.com/t/using-ecto-to-run-a-long-running-multi-process-transaction/4365/18. Basically, if I understood it correctly, the only potential 'fix' is writing your own Ecto adapter similar to Sandbox adapter that would allow interactions with connections somehow.
So I think you're right, the only thing that is feasible to do is to put into docs the note that one should not expect that insert/update SQL queries in run_async
stages are going to be rolled back in the case when saga fails.
@gaynetdinov I'll leave this open if somebody is willing to contribute a Sage.Ecto.SQLSandbox
for async stages but realistically It's a thing that can be hard to maintain (I'm trying to keep sage as simple as possible so that it's less error-prone).
And I'll go and add docs about that. Thank you for findings this again ❤️.
Added a note in https://github.com/Nebo15/sage/commit/94b420a87802e8067617544add7c0d37a5a2222d, please take a look and tell if it's not clear enough.
It looks clear to me 👌 Thank you!
Hi!
Do I understand correctly that even if I call
Sage.transaction
in my saga, my SQL changes inrun_async
stages are not going to be rolled back due to the fact, thatrepo.transaction/2
andrepo.rollback/1
are executed in the 'main' process whilerun_async
step is executed in another process viaTask.async
? My understanding is that the task process would checkout new connection from ecto pool, run the queries and that's it. The transaction/rollback function calls are happening outside of the async process within different database connection, therefore the changes made in async stage are not going to be rolled back.Thank you for your time!