This repository was archived by the owner on Mar 4, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 113
This repository was archived by the owner on Mar 4, 2026. It is now read-only.
Uncaught exception with concurrent queries and inline begin #1972
Copy link
Copy link
Closed
Labels
api: spannerIssues related to the googleapis/nodejs-spanner API.Issues related to the googleapis/nodejs-spanner API.priority: p2Moderately-important priority. Fix may not be included in next release.Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Description
The client throws an unhandled exception if the initial queries in the transaction are called concurrently and one of the queries fails(except for the first one). You can see the example below. The issue is resolved if transaction.begin() is called explicitly before the concurrent queries.
Environment details
- OS: macOS 14.2 (23C64)
- Node.js version: v20.1.0
- npm version: 9.6.4
@google-cloud/spannerversion: reproducible on master
Steps to reproduce
Minimal repro
// We discovered this issue with ABORTED errors, but
// it's easier to reproduce with this non-existent table query.
const nonExistantTableQuery = 'SELECT * FROM nonExistingTable';
await database.runTransactionAsync(async tx => {
try {
await Promise.all([
tx!.run(selectSql),
tx!.run(nonExistantTableQuery),
]);
await tx.commit();
} catch (err) {
await tx.rollback();
}
});This code will result in an uncaught exception and it will crash node process.
I think the issue is a missing error handler in this code.
nodejs-spanner/src/transaction.ts
Lines 1336 to 1338 in 6c0eef1
| makeRequest(resumeToken) | |
| .on('data', chunk => streamProxy.emit('data', chunk)) | |
| .on('end', () => streamProxy.emit('end')); |
Adding this handler fixes the issue
.on('error', err => streamProxy.emit('error', err))Happy to open PR with test if this seems correct
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
api: spannerIssues related to the googleapis/nodejs-spanner API.Issues related to the googleapis/nodejs-spanner API.priority: p2Moderately-important priority. Fix may not be included in next release.Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.Error or flaw in code with unintended results or allowing sub-optimal usage patterns.