这是indexloc提供的服务,不要输入任何密码
Skip to content

Possible race condition in postgresql type_map initialization #51780

@scpike

Description

@scpike

Steps to reproduce

Since upgrading from Rails 7.0 to 7.1 we've started to see the following exception:

# activerecord (7.1.3.2) lib/active_record/connection_adapters/postgresql_adapter.rb in get_oid_type
undefined method `key?' for nil:NilClass (NoMethodError)
          if !type_map.key?(oid)
                      ^^^^^

I haven't been able to replicate the behavior outside of production where it occurs when the application briefly loses its connection to the postgres database while under load. This is a multi-threaded environment. The server never recovers after entering this state.

I know there was a change to type_map initialization at dc4420c, and it looks to me like it's possible there's a race condition here. I'll update this issue with steps to replicate if I can manage to trigger this outside of production.

Expected behavior

The application should recover from a brief database outage and reconnect.

Actual behavior

The server is never able to reconnect.

System configuration

Rails version: 7.1.3.2

Ruby version: 3.2.4

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions