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

docs: fix bug in transaction example #3414

Merged
merged 1 commit into from
Apr 1, 2025
Merged

Conversation

lucaesposto
Copy link
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
Owner

brianc commented Apr 1, 2025

ah you're totally right - sorry about that!

@brianc
Copy link
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
Owner

brianc commented Apr 1, 2025

badda boom! ty!

@charmander
Copy link
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