Skip to content

Disconnect if configure_connection failed#54711

Merged
byroot merged 1 commit intorails:mainfrom
byroot:ensure-configured-connection
Mar 7, 2025
Merged

Disconnect if configure_connection failed#54711
byroot merged 1 commit intorails:mainfrom
byroot:ensure-configured-connection

Conversation

@byroot
Copy link
Copy Markdown
Member

@byroot byroot commented Mar 7, 2025

Fix: #51780

There are a number of scenarios in which one of the queries performed as part of configure_connection fails, and leave the Adapter in an half initialized state.

Up to Rails 7.0, this could likely happen during a call to reconnect!, so relatively rare. For the more classic initial connection, the Adapter instance would only be added to the pool on a successful connect.

But in 7.1 I made the connection fully lazy, meaning the Adapter instance is now added to the pool before attempting to connect.

This made this bug much more likely.

The solution is to disconnect if configure_connection raises an error. This way on a retry we'll reconnect and reconfigure from scratch.

Fix: rails#51780

There are a number of scenarios in which one of the queries performed
as part of `configure_connection` fails, and leave the `Adapter`
in an half initialized state.

Up to Rails 7.0, this could likely happen during a call to `reconnect!`,
so relatively rare. For the more classic initial connection,
the `Adapter` instance would only be added to the pool on a successful
connect.

But in 7.1 I made the connection fully lazy, meaning the `Adapter`
instance is now added to the pool before attempting to connect.

This made this bug much more likely.

The solution is to disconnect if `configure_connection` raises an error.
This way on a retry we'll reconnect and reconfigure from scratch.
@byroot byroot merged commit c20f7ce into rails:main Mar 7, 2025
3 checks passed
byroot added a commit that referenced this pull request Mar 7, 2025
Disconnect if `configure_connection` failed
byroot added a commit that referenced this pull request Mar 7, 2025
Disconnect if `configure_connection` failed
matthewd added a commit to matthewd/rails that referenced this pull request Apr 27, 2025
…connection"

This reverts commit c20f7ce, reversing
changes made to aa2bfad.
peter-evans added a commit to peter-evans/rails that referenced this pull request Apr 28, 2025
…connection"

This reverts commit c20f7ce, reversing
changes made to aa2bfad.
mgriffin added a commit to mgriffin/rails that referenced this pull request Apr 28, 2025
…connection"

This reverts commit c20f7ce, reversing
changes made to aa2bfad.
peter-evans added a commit to peter-evans/rails that referenced this pull request Apr 28, 2025
…connection"

This reverts commit c20f7ce, reversing
changes made to aa2bfad.
peter-evans added a commit to peter-evans/rails that referenced this pull request May 1, 2025
…connection"

This reverts commit c20f7ce, reversing
changes made to aa2bfad.
mgriffin added a commit to mgriffin/rails that referenced this pull request May 6, 2025
…connection"

This reverts commit c20f7ce, reversing
changes made to aa2bfad.
mgriffin added a commit to mgriffin/rails that referenced this pull request May 8, 2025
…connection"

This reverts commit c20f7ce, reversing
changes made to aa2bfad.
peter-evans added a commit to peter-evans/rails that referenced this pull request May 12, 2025
…connection"

This reverts commit c20f7ce, reversing
changes made to aa2bfad.
peter-evans added a commit to peter-evans/rails that referenced this pull request May 12, 2025
…connection"

This reverts commit c20f7ce, reversing
changes made to aa2bfad.
mgriffin added a commit to mgriffin/rails that referenced this pull request May 15, 2025
…connection"

This reverts commit c20f7ce, reversing
changes made to aa2bfad.
peter-evans added a commit to peter-evans/rails that referenced this pull request May 26, 2025
…connection"

This reverts commit c20f7ce, reversing
changes made to aa2bfad.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Possible race condition in postgresql type_map initialization

1 participant