Skip to content

Commit

Permalink
More span.end() checks
Browse files Browse the repository at this point in the history
  • Loading branch information
odeke-em committed Oct 21, 2024
1 parent a3589e5 commit e0e31f5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
1 change: 0 additions & 1 deletion observability-test/spanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2177,7 +2177,6 @@ describe('Traces for ExecuteStream broken stream retries', () => {
await tx!.runUpdate(insertSql, err => {
assert.ok(err, 'Missing expected error');
assert.strictEqual(err!.code, grpc.status.INVALID_ARGUMENT);
console.log('Got expected error');
assert.strictEqual(attempts, 1);
tx!
.commit()
Expand Down
24 changes: 19 additions & 5 deletions src/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2101,6 +2101,9 @@ class Database extends common.GrpcServiceObject {
session!.lastError = err;
this.pool_.release(session!);
this.getSnapshot(options, (err, snapshot) => {
if (err) {
setSpanError(span, err);
}
span.end();
callback!(err, snapshot);
});
Expand Down Expand Up @@ -3223,7 +3226,8 @@ class Database extends common.GrpcServiceObject {
txn!.once('end', () => {
span.end();
});
txn!.once('error', () => {
txn!.once('error', err => {
setSpanError(span, err!);
span.end();
});
runFn!(null, txn!);
Expand All @@ -3245,8 +3249,6 @@ class Database extends common.GrpcServiceObject {
}

if (err) {
// This code path failed to even begin running the transaction
// hence end the span immediately and return it.
span.end();
runFn!(err as grpc.ServiceError);
return;
Expand Down Expand Up @@ -3553,6 +3555,11 @@ class Database extends common.GrpcServiceObject {
mutationGroups,
options
);
dataStream.once('end', () => span.end());
dataStream.once('error', err => {
setSpanError(span, err!);
span.end();
});
dataStream.pipe(proxyStream);
} else {
span.end();
Expand Down Expand Up @@ -3652,10 +3659,17 @@ class Database extends common.GrpcServiceObject {
span.addEvent('No session available', {
'session.id': session?.id,
});
this.writeAtLeastOnce(mutations, options, cb!);
span.end();
// Retry this method.
this.writeAtLeastOnce(mutations, options, (err, resp) => {
if (err) {
setSpanError(span, err);
}
span.end();
cb!(err, resp);
});
return;
}

if (err) {
setSpanError(span, err);
span.end();
Expand Down

0 comments on commit e0e31f5

Please sign in to comment.