Skip to content

docs: fix bug in transaction example#3414

Merged
brianc merged 1 commit intobrianc:masterfrom
lucaesposto:patch-1
Apr 1, 2025
Merged

docs: fix bug in transaction example#3414
brianc merged 1 commit intobrianc:masterfrom
lucaesposto:patch-1

Conversation

@lucaesposto
Copy link
Copy Markdown
Contributor

Throwing error will not allow "finally" execution, so client.release() must be invoked before it.

Here a very simple example of JS behaviour:

try {
  console.log('init');
  throw new Error('TestError');
} catch (e) {
  console.log('catch'); / prints "Error: TestError"
  throw e
} finally {
  console.log('finally'); // not printed
}

I know this is an easy catch for experienced js developers, nevertheless i'm afraid providing this bugged example will cause (and caused) a lot of subtle bugs into beginners code.

Throwing error will not allow "finally" execution, so client.release() must be invoked before it.
@brianc
Copy link
Copy Markdown
Owner

brianc commented Apr 1, 2025

ah you're totally right - sorry about that!

@brianc
Copy link
Copy Markdown
Owner

brianc commented Apr 1, 2025

rerunning the failed job - sometimes tests timeout depending on infra issues...sucks but since some of the tests actually test timeouts its a bit of a catch-22 to try & fix (unless it happens regularly)

@brianc brianc merged commit dcb4257 into brianc:master Apr 1, 2025
11 of 12 checks passed
@brianc
Copy link
Copy Markdown
Owner

brianc commented Apr 1, 2025

badda boom! ty!

@charmander
Copy link
Copy Markdown
Collaborator

Throwing error will not allow "finally" execution, so client.release() must be invoked before it.

Here a very simple example of JS behaviour:

try {
  console.log('init');
  throw new Error('TestError');
} catch (e) {
  console.log('catch'); / prints "Error: TestError"
  throw e
} finally {
  console.log('finally'); // not printed
}
> try {
  console.log('init');
  throw new Error('TestError');
} catch (e) {
  console.log('catch');
  throw e
} finally {
  console.log('finally');
}

init
catch
finally
Uncaught Error: TestError
    at <anonymous>:3:9

charmander added a commit that referenced this pull request Apr 3, 2025
This reverts commit dcb4257.

The change doesn’t fix the bug it claims to (`finally` always runs) and introduces a resource leak if the `ROLLBACK` query fails. The related bug that a broken client can be returned to the pool remains unaffected either way.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants