Skip to content

Fiber-aware I18n config storage #731

Open
lee266 wants to merge 5 commits intoruby-i18n:masterfrom
lee266:feature/fiber-storage
Open

Fiber-aware I18n config storage #731
lee266 wants to merge 5 commits intoruby-i18n:masterfrom
lee266:feature/fiber-storage

Conversation

@lee266
Copy link
Copy Markdown
Contributor

@lee266 lee266 commented Feb 15, 2026

This PR improves I18n.locale/config behavior in Fiber-based runtimes:

  • Thread.current[:i18n_config] is fiber-local, so entering a new Fiber can “lose” locale/config and fall back to default_locale (e.g. CSV/Enumerator creating Fibers).
  • A true thread-local (Thread#thread_variable_*) avoids that, but can cause cross-request locale leakage in fiber-per-request servers (e.g. Falcon).

What this PR does

  • Use Fiber storage (Fiber[]) when available to preserve locale/config across child Fibers.
  • Add Copy-on-Write so writes (e.g. I18n.locale=) don’t mutate shared state: Config#set! freezes the stored config, and setters duplicate as needed before mutating.
  • Keep a fallback path for environments without Fiber storage.

I’m still unsure whether i18n should require Ruby 3.2+ (so Fiber storage is always available) or keep supporting older Rubies with the fallback path; feedback welcome.

issue: #723

@lee266 lee266 force-pushed the feature/fiber-storage branch from afb8b57 to 14b8f9a Compare February 15, 2026 14:21
@lee266 lee266 changed the title Fiber-aware I18n config storage draft: Fiber-aware I18n config storage Feb 15, 2026
@lee266
Copy link
Copy Markdown
Contributor Author

lee266 commented Feb 15, 2026

507a88e needs fix other issues

README.md is same

@ioquatix
Copy link
Copy Markdown

ioquatix commented Feb 16, 2026

You can use this shim for older Ruby versions: https://rubygems.org/gems/fiber-storage

It doesn't work in C code that creates fibers, e.g. enumerators, but it works for everything else. IOW, you can code to the spec, and users can upgrade Ruby if that is a deal breaker.

@lee266 lee266 force-pushed the feature/fiber-storage branch from 3e2dc1e to bfc992d Compare February 23, 2026 15:46
@lee266
Copy link
Copy Markdown
Contributor Author

lee266 commented Feb 23, 2026

@ioquatix
Thanks for the suggestion — this is very helpful.

I’ve updated it to use a Fiber-based approach and to support Ruby >= 3.2, and removed the extra legacy compatibility checks.

Do you think we should also document a workaround path for older Rubies (for example, mentioning fiber-storage as an optional app-level shim), or should we keep the docs focused only on officially supported versions?

@ioquatix
Copy link
Copy Markdown

ioquatix commented Feb 24, 2026

If it was me personally, I am dropping support for 3.2 at the end of March (it's published EOL for security updates). I simply don't have capacity to maintain backwards compatibility, so I'd suggest you do the same. People can always use old releases. That's my personal philosophy.

@lee266 lee266 changed the title draft: Fiber-aware I18n config storage Fiber-aware I18n config storage Mar 14, 2026
@travisbell
Copy link
Copy Markdown

@lee266 @radar Is there anything stopping us from pushing this forward?

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.

3 participants