Skip to content

Pre-load AR schemas and disconnect before forking DSL workers#2522

Open
paracycle wants to merge 1 commit intomainfrom
uk/preload-schemas-and-disconnect-before-fork
Open

Pre-load AR schemas and disconnect before forking DSL workers#2522
paracycle wants to merge 1 commit intomainfrom
uk/preload-schemas-and-disconnect-before-fork

Conversation

@paracycle
Copy link
Member

Motivation

With multiple workers, we've been hitting connection limits on CI when verifying DSL RBI files. This PR attempts to fix that problem.

Implementation

Pre-load the schema for all ActiveRecord models in the parent process before forking parallel workers, so the schema cache is inherited via copy-on-write. Then clear all database connections so forked children don't inherit stale connections from the parent. Together, this should ensure that child processes do not make any database connections, since most of our introspection should just be hitting the schema.

Tests

No new tests.

Pre-load the schema for all ActiveRecord models in the parent process
before forking parallel workers, so the schema cache is inherited via
copy-on-write. Then clear all database connections so forked children
don't inherit stale connections from the parent, avoiding exceeding
connection limits (e.g. Semian ticket counts).
@paracycle paracycle requested a review from Morriar March 4, 2026 16:51
@paracycle paracycle requested a review from a team as a code owner March 4, 2026 16:51
# Disconnect all database connections before forking workers. The migration check and schema pre-loading
# above may have established connections; clearing them ensures forked children don't inherit stale
# connections from the parent, avoiding exceeding connection limits (e.g. Semian ticket counts).
::ActiveRecord::Base.connection_handler.clear_all_connections!
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this even with @number_of_workers == 1?

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.

2 participants