mirror of
https://github.com/discourse/discourse.git
synced 2025-06-01 09:08:10 +08:00
DEV: Use MiniSql ActiveRecordPostgres adapter (#15767)
This adapter ensures that MiniSql locks the ActiveRecord mutex before using the raw PG connection. This ensures that multiple threads will not attempt to use the same connection simultaneously. This commit also removes the schema_cache_concurrency freedom-patch, which is no longer required now that cross-thread connection use is controlled by the mutex. For the original root cause of this issue, see https://github.com/rails/rails/pull/38577
This commit is contained in:
@ -1,27 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
#
|
||||
# Rails has a circular dependency in SchemaCache.
|
||||
# In certain situation SchemaCache can carry a @connection
|
||||
# from a different thread. This causes potential concurrency bugs
|
||||
# in Sidekiq.
|
||||
#
|
||||
# This patches it so it is less flexible (theoretically) but always bound to the current connection
|
||||
|
||||
# This patch needs to be reviewed in future versions of Rails.
|
||||
# We should consider upstreaming this optionally.
|
||||
|
||||
module ActiveRecord
|
||||
module ConnectionAdapters
|
||||
class SchemaCache
|
||||
|
||||
def connection=(connection)
|
||||
# AbstractPool get_schema_cache does schema_cache.connection = connection
|
||||
Thread.current["schema_cached_connection"] = connection
|
||||
end
|
||||
|
||||
def connection
|
||||
Thread.current["schema_cached_connection"]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user