Skip to content

Conversation

@jeremy
Copy link
Member

@jeremy jeremy commented Dec 8, 2025

When ActiveStorage::Record uses connects_to for read replica support, it creates a separate connection pool from ApplicationRecord. This causes after_commit callbacks to fire in non-deterministic order - the Attachment's create_variants callback can fire before the User model's upload callback completes, resulting in FileNotFoundError.

The fix removes replica connection configuration from ActiveStorage::Record so it shares the same connection pool as application models, ensuring proper callback ordering.

Also reverts test workarounds that were added to work around this issue, since the root cause is now fixed.

See: rails/rails#53694

/cc @basecamp/sip @jorgemanrubia

When ActiveStorage::Record uses `connects_to` for read replica support,
it creates a separate connection pool from ApplicationRecord. This causes
`after_commit` callbacks to fire in non-deterministic order - the
Attachment's `create_variants` callback can fire before the User model's
upload callback completes, resulting in FileNotFoundError.

The fix removes replica connection configuration from ActiveStorage::Record
so it shares the same connection pool as application models, ensuring
proper callback ordering.

Also reverts test workarounds that were added to work around this issue,
since the root cause is now fixed.

See: rails/rails#53694
@jeremy jeremy merged commit 49c4f2a into main Dec 8, 2025
8 of 10 checks passed
@jeremy jeremy deleted the ast-conn-pool branch December 8, 2025 22:44
adjogima added a commit that referenced this pull request Dec 9, 2025
* main: (70 commits)
  bin/ci: run OSS suite in SAAS mode for full coverage (#2029)
  Fix flaky tests caused by leaky show_exceptions twiddling (#2028)
  Fix ActiveStorage FileNotFoundError with immediate variant processing (#2022)
  Immediate avatar and embed variants (#2002)
  Should be in global gitignore
  Account for browser button styled and adjust mobile padding for perma BG
  Wrap the overflow menu
  doc: update style doc reference for LLM agents
  Fix Identity destruction callback ordering
  Ensure user toggles on board edit page are cached properly
  Adopt a cooldown period for dependency updates
  Add lazy error context for Rails error reporter (#2014)
  Disable board edit buttons for select all/none when not privileged
  Autotuner: use structured logging instead of Sentry (#2011)
  Add datetime to the search results
  Fix involvement button label
  Bump mittens to 0.3.1 (#2006)
  No need to pass Currentl.user since it is the default value for the param
  Validate email before creating identity during join code redemption
  Ignore RubyMine project files in .gitignore
  ...
adjogima added a commit that referenced this pull request Dec 9, 2025
…tylesheets+edits

* mobile-app/scoped-stylesheets: (77 commits)
  Stream response in webhook request manually to check size
  Fix stale-read race when creating push subscriptions
  stylesheet_paths is the only public method
  Use development instead of local
  Drop defunct Account upload attachments (#2030)
  Process blob variants using local files
  bin/ci: run OSS suite in SAAS mode for full coverage (#2029)
  Fix flaky tests caused by leaky show_exceptions twiddling (#2028)
  Fix ActiveStorage FileNotFoundError with immediate variant processing (#2022)
  Immediate avatar and embed variants (#2002)
  Should be in global gitignore
  Account for browser button styled and adjust mobile padding for perma BG
  Wrap the overflow menu
  Allow configuring SSL in production with ENV vars
  doc: update style doc reference for LLM agents
  Fix Identity destruction callback ordering
  Ensure user toggles on board edit page are cached properly
  Adopt a cooldown period for dependency updates
  Add lazy error context for Rails error reporter (#2014)
  Disable board edit buttons for select all/none when not privileged
  ...
lonexw pushed a commit to lonexw/kanban that referenced this pull request Dec 9, 2025
…basecamp#2022)

When ActiveStorage::Record uses `connects_to` for read replica support,
it creates a separate connection pool from ApplicationRecord. This causes
`after_commit` callbacks to fire in non-deterministic order - the
Attachment's `create_variants` callback can fire before the User model's
upload callback completes, resulting in FileNotFoundError.

The fix removes replica connection configuration from ActiveStorage::Record
so it shares the same connection pool as application models, ensuring
proper callback ordering.

Also reverts test workarounds that were added to work around this issue,
since the root cause is now fixed.

See: rails/rails#53694
jorgemanrubia added a commit that referenced this pull request Dec 9, 2025
* main: (78 commits)
  Make SMTP config conditional on SMTP_ADDRESS
  default to smtp
  configurable actionmailer settings (ENV)
  Stream response in webhook request manually to check size
  Fix stale-read race when creating push subscriptions
  Drop defunct Account upload attachments (#2030)
  Process blob variants using local files
  bin/ci: run OSS suite in SAAS mode for full coverage (#2029)
  Fix flaky tests caused by leaky show_exceptions twiddling (#2028)
  Fix ActiveStorage FileNotFoundError with immediate variant processing (#2022)
  Immediate avatar and embed variants (#2002)
  Should be in global gitignore
  Account for browser button styled and adjust mobile padding for perma BG
  Wrap the overflow menu
  Allow configuring SSL in production with ENV vars
  doc: update style doc reference for LLM agents
  Fix Identity destruction callback ordering
  Ensure user toggles on board edit page are cached properly
  Adopt a cooldown period for dependency updates
  Add lazy error context for Rails error reporter (#2014)
  ...

# Conflicts:
#	Gemfile.saas.lock
#	db/schema.rb
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