googleapis / nodejs-spanner

Node.js client for Google Cloud Spanner: the world’s first fully managed relational database service to offer both strong consistency and horizontal scalability.
https://cloud.google.com/spanner/
Apache License 2.0
135 stars 99 forks source link

Unhandled exception when running parallel queries with first query as "invalid" in a transaction. #2092

Open surbhigarg92 opened 1 month ago

surbhigarg92 commented 1 month ago

The Nodejs library does not handle below scenario, where the first query throws an error while trying to execute parallel queries in a transaction .

await database.runTransactionAsync(async tx => {
        try {
          await Promise.all([tx!.run(invalidSql), tx!.run(selectSql)]);
          await tx.commit();
        } catch (err) {
          console.log(err);
        }

Expected: The initial call to ExecuteStreamingSql should fail, which also means that there is no transaction ID that is returned. The transaction is retried with an explicit BeginTransaction and then the invalid SQL + working SQL statement are executed again. Error will be thrown from the invalid SQL statement.

Actual: The initial call to ExecuteStreamingSql fails which initiates a explicit BeginTransaction as per this code . But since this request is not awaited, error is thrown to the catch block and begin transaction continues in parallel , ultimately throwing unhandled exception.