Skip to content
This repository was archived by the owner on May 22, 2021. It is now read-only.
This repository was archived by the owner on May 22, 2021. It is now read-only.

Review connection pool implementation #8

@ioquatix

Description

@ioquatix

Regarding rails/rails#37070 I realised maybe it's possible for long running queries to overlap because the ConnectionPool is storing connections seemingly per-thread. So even if you start a transaction in different fibers, maybe it breaks.

      # Retrieve the connection associated with the current thread, or call
      # #checkout to obtain one if necessary.
      #
      # #connection can be called any number of times; the connection is
      # held in a cache keyed by a thread.
      def connection
        @thread_cached_conns[connection_cache_key(current_thread)] ||= checkout
      end

One option is to try and hijack the ConnectionPool - e.g. if spec[:connection_pool] is defined, use it.

        message_bus.instrument("!connection.active_record", payload) do
          owner_to_pool[spec.name] = ConnectionAdapters::ConnectionPool.new(spec)
        end

It seems to me, a per-fiber or per-thread connection pool might make more sense.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions