Skip to content
This repository was archived by the owner on Mar 4, 2026. It is now read-only.
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

@grosto

Description

@grosto

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/spanner version: 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.

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

Metadata

Metadata

Assignees

Labels

api: spannerIssues related to the googleapis/nodejs-spanner API.priority: p2Moderately-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.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions