Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncaught exception with concurrent queries and inline begin #1972

Open
grosto opened this issue Dec 18, 2023 · 1 comment
Open

Uncaught exception with concurrent queries and inline begin #1972

grosto opened this issue Dec 18, 2023 · 1 comment
Assignees
Labels
api: spanner Issues related to the googleapis/nodejs-spanner API. priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@grosto
Copy link

grosto commented Dec 18, 2023

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

@grosto grosto added priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels Dec 18, 2023
@product-auto-label product-auto-label bot added the api: spanner Issues related to the googleapis/nodejs-spanner API. label Dec 18, 2023
@surbhigarg92
Copy link
Contributor

Hi @grosto Thanks for raising this bug and identifying the root cause. This looks correct to me. Please feel free to raise the PR if you wish. Else I will take this up in new year 1st week.

@surbhigarg92 surbhigarg92 self-assigned this Mar 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: spanner Issues related to the googleapis/nodejs-spanner API. priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

No branches or pull requests

2 participants