Skip to content

Commit

Permalink
For retried Transaction.commit, end only on completion
Browse files Browse the repository at this point in the history
  • Loading branch information
odeke-em committed Oct 8, 2024
1 parent 1e82b91 commit 3d5fa6c
Showing 1 changed file with 27 additions and 16 deletions.
43 changes: 27 additions & 16 deletions src/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -719,13 +719,16 @@ export class Snapshot extends EventEmitter {

const traceConfig = {tableName: table, opts: this._observabilityOptions};
return startTrace('Snapshot.createReadStream', traceConfig, span => {
const resultStream = partialResultStream(this._wrapWithIdWaiter(makeRequest), {
json,
jsonOptions,
maxResumeRetries,
columnsMetadata,
gaxOptions,
})
const resultStream = partialResultStream(
this._wrapWithIdWaiter(makeRequest),
{
json,
jsonOptions,
maxResumeRetries,
columnsMetadata,
gaxOptions,
}
)
?.on('response', response => {
if (response.metadata && response.metadata!.transaction && !this.id) {
this._update(response.metadata!.transaction);
Expand Down Expand Up @@ -1283,13 +1286,16 @@ export class Snapshot extends EventEmitter {
});
};

const resultStream = partialResultStream(this._wrapWithIdWaiter(makeRequest), {
json,
jsonOptions,
maxResumeRetries,
columnsMetadata,
gaxOptions,
})
const resultStream = partialResultStream(
this._wrapWithIdWaiter(makeRequest),
{
json,
jsonOptions,
maxResumeRetries,
columnsMetadata,
gaxOptions,
}
)
.on('response', response => {
if (response.metadata && response.metadata!.transaction && !this.id) {
this._update(response.metadata!.transaction);
Expand Down Expand Up @@ -2080,8 +2086,13 @@ export class Transaction extends Dml {
reqOpts.singleUseTransaction = this._options;
} else {
this.begin().then(() => {
span.end();
this.commit(options, callback);
this.commit(options, (err, resp) => {
if (err) {
setSpanError(span, err);
}
span.end();
callback(err, resp);
});
}, callback);
return;
}
Expand Down

0 comments on commit 3d5fa6c

Please sign in to comment.