-
Notifications
You must be signed in to change notification settings - Fork 217
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Duplicated save-point names in parallel sub-transactions #774
Comments
Thanks for opening a new issue. The team has been notified and will review it as soon as possible. |
You need to chain your helper functions correctly, supporting optional transaction context, then it will work as expected. If you include simplified version of those here, then I can show what's wrong with them. |
I know I can use |
As I explained earlier, most likely you are not chaining them correctly. I cannot be more accurate, since you are not providing the troubling code example. Include the code, then we should make progress here.
That would imply that invalid transaction chaining is ok, but it is not. Let's not jump ahead of ourselves, and look at the actual code first, which you should provide. |
@Tol1 Are you still planning to add a code example? If not, then we should close it, because we cannot make progress without one. |
Closing, because no functioning example provided. |
Since the author failed to provide any code example, I finally got time to try and produce the issue myself... I can confirm that now that if you try to execute multiple sub-transactions in parallel, the save-points end up with overlapping names, which results in invalid release of save-points.
It's not that documentation isn't clear enough, it didn't account for that special case, neither did the tests. So you can consider that a bug or limitation, though the use case is quite unique. Also, it has a simple work-around, by using the i.e. you take the following problematic code: db.tx(t => {
const a = t.tx(t1 => { });
const b = t.tx(t1 => { });
const c = t.tx(t1 => { });
return t.batch([a, b, c]);
}) =>
and replace it with this: db.tx(async t => {
const a = await t.tx(t1 => { });
const b = await t.tx(t1 => { });
const c = await t.tx(t1 => { });
return {a, b, c};
}) =>
and then no more problem. I may later at some point look into improving the library, to make save points fully unique. |
After a bit more investigation, I'm going to close this again, because trying to parallel sub-transactions via Consider the following SQL: begin;
savepoint one;
savepoint two;
release savepoint one;
release savepoint two;
commit; It will throw error on line This is what will keep happening, if you try parallel savepoints inside a transaction, you will always lose control of savepoints nesting logic. Therefore, you should never do that to begin with, and just sync sub-transactions, using |
In version 10.9.3, I changed how savepoints are named - see Transaction Limitations. Savepoints now use format |
I have 3 helper functions,
A
,B
andC
, and all of them start transaction, for they can all be called individually.A
callsC
, so whenA
is called,C
starts savepoint with namelevel_1
.Then I have one case, where I call both
A
andB
in same time, using functionD
. I want everyting to be run in transaction, soD
starts transaction, and callsA
andB
usingPromise.all
.Now comes the problem: Both
A
andB
start a savepoint with namelevel_1
, andC
starts a savepoint with namelevel_2
. Per postgresql spec, if duplicate savepoint names are used,RELEASE SAVEPOINT
releases last defined savepoint first. Now I can end in situation, where finishingB
releases savepoint defined inA
, and thus releases also sub-savepoint defined inC
, giving me errorno such savepoint
whenC
actually finishes.Everything works when calling
A
andC
sequentically, but this made us scratch our heads when searching for unhandled promises.Expected behavior
Every savepoint gets an unique name
Actual behavior
Savepoints get unique name only on current branch
Environment
The text was updated successfully, but these errors were encountered: