# ActiveRecord::StatementInvalid / Mysql2 Fiber connection error after upgrading to Rails 8.1

**URL:** <https://discuss.rubyonrails.org/t/activerecord-statementinvalid-mysql2-fiber-connection-error-after-upgrading-to-rails-8-1/91272>\
**Category:** rubyonrails-talk\
**Created:** [June 30, 2026, 9:15am UTC](https://discuss.rubyonrails.org/t/activerecord-statementinvalid-mysql2-fiber-connection-error-after-upgrading-to-rails-8-1/91272 "2026-06-30T09:15:36Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![dosapativ](https://avatars.discourse-cdn.com/v4/letter/d/c89c15/32.png) [@dosapativ](https://discuss.rubyonrails.org/u/dosapativ)\
**Post date:** [June 30, 2026, 9:15am UTC](https://discuss.rubyonrails.org/t/activerecord-statementinvalid-mysql2-fiber-connection-error-after-upgrading-to-rails-8-1/91272/1 "2026-06-30T09:15:36Z")

</div>

Hi all,

After upgrading a large production app from Rails 7.0.4 / Ruby 3.0.2 to Rails 8.1.2.1 / Ruby 3.4.8, we started seeing intermittent DB connection ownership errors that were not present before.

Error with mysql2:

```ruby
ActiveRecord::StatementInvalid:
Mysql2::Error: This connection is in use by: #<Fiber:... (resumed)>

```

We also tried switching from `mysql2` to `trilogy` (2.12) and saw a similar error:

```ruby
ActiveRecord::StatementInvalid:
Trilogy::SynchronizationError: This connection is already in use by another thread or fiber

```

Environment:

- Rails 8.1.2.1

- Ruby 3.4.8

- mysql2 0.5.7

- MySQL

- Puma 6.4.3

- Delayed Job

We have not intentionally introduced new concurrency primitives, so we’re trying to understand whether Rails 8.1 is exposing a pre-existing issue in our app, or whether there were changes in ActiveRecord connection ownership / fiber handling between Rails 7.x and 8.1 that could explain this.

We do not yet have a minimal reproduction, but we can share a full stack trace if helpful.

Has anyone seen this after upgrading to Rails 8.1 or Ruby 3.4? Also, is there a recommended way to identify which fiber/code path is retaining the connection?

Thanks.
