Skip to content

Commit b3e1c01

Browse files
committed
fix: do not remove session tx id if txMeta empty.
Signed-off-by: Vladislav Polyakov <[email protected]>
1 parent bc041c3 commit b3e1c01

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

src/query/query-client.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
sessionCurrentOperationSymbol,
1111
sessionReleaseSymbol, isIdempotentSymbol, isIdempotentDoLevelSymbol, ctxSymbol
1212
} from "./symbols";
13-
import {BadSession, SessionBusy} from "../errors";
13+
import {YdbError} from "../errors";
1414
import {Context} from "../context";
1515
import {ensureContext} from "../context";
1616
import {Logger} from "../logger/simple-logger";
@@ -71,8 +71,8 @@ export class QueryClient extends EventEmitter {
7171
try {
7272
res = await opts.fn(session);
7373
} catch (err) {
74-
if (session[sessionTxIdSymbol] && !(err instanceof BadSession || err instanceof SessionBusy)) {
75-
await session[sessionRollbackTransactionSymbol]();
74+
if (err instanceof YdbError) {
75+
delete session[sessionTxIdSymbol];
7676
}
7777
throw err;
7878
}

src/query/query-session-execute.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -195,13 +195,13 @@ export function execute(this: QuerySession, args: IExecuteArgs): Promise<IExecut
195195
try {
196196
ensureCallSucceeded(partialResp);
197197
} catch (ydbErr) {
198+
delete this[sessionTxIdSymbol]
199+
198200
return cancel(ydbErr);
199201
}
200202

201203
if (partialResp.txMeta?.id)
202204
this[sessionTxIdSymbol] = partialResp.txMeta!.id;
203-
else
204-
delete this[sessionTxIdSymbol];
205205

206206
if (partialResp.resultSet) {
207207

@@ -312,6 +312,10 @@ export function execute(this: QuerySession, args: IExecuteArgs): Promise<IExecut
312312
resultResolve = resultReject = undefined;
313313
}
314314

315+
if (args.txControl?.commitTx) {
316+
delete this[sessionTxIdSymbol]
317+
}
318+
315319
if (finishedResolve) finishedResolve();
316320
delete this[sessionCurrentOperationSymbol];
317321
if (unsub) unsub();

0 commit comments

Comments
 (0)