database.run(...) hangs for a few seconds with invalid query
database.run(...) hangs for a few seconds when an invalid query is passed.
Environment details
- OS: M1 Mac
- Node.js version: 20.7.0
- npm version: 10.1.0
@google-cloud/spannerversion: ^7.5.0- spanner emulator version: 1.5.13
Steps to reproduce
I created minimum reproducible code: https://github.com/ikenox/nodejs-spanner-example/tree/hangs-with-invalid-query
git clone [email protected]:ikenox/nodejs-spanner-example.git
git checkout hangs-with-invalid-query
pnpm install
gcloud emulators spanner start &
SPANNER_EMULATOR_HOST=localhost:9010 pnpm exec ts-node src/main.ts
main.ts executes the code like below.
console.time('valid query');
await database.run('select 1');
console.timeEnd('valid query');
console.time('invalid query');
try{
await database.run('select aaa');
}catch(e){
console.log(e);
}
console.timeEnd('invalid query');
And the output is below:
valid query: 21.579ms
3 INVALID_ARGUMENT: Unrecognized name: aaa [at 1:8]
select aaa
^
invalid query: 7.406s
@ikenox I verified this , I am able to reproduce this issue with Emulator. But when I using Spanner database directly the command is not hanging.
This is probably related to #1444. I still get those unwanted retries when I (accidentally) write an invalid query and run tests. Not the end of the world as those invalid queries are fixed right away and this never happens in production. However it makes debugging quite frustrating as the retry mechanism takes longer than the default timeout for tests (e.g. in Jest). I don't understand why this is happening, as the emulator does return the correct statuses, which shouldn't be retried.