GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — I18n::Backend::Memoize is not thread-safe by thedarkone · Pull Request #51 · ruby-i18n/i18n

Conversation

@thedarkone

@thedarkone thedarkone commented Sep 29, 2013

Copy link
Copy Markdown
Contributor

Backend::Memoize uses a plain Hash that is shared between all threads, this is obviously not thread-safe and the module can't be used in truly threaded environments such as JRuby.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@josevalim

josevalim commented Aug 30, 2010

Copy link
Copy Markdown
Contributor

Is there an easy way for us to solve this which does not require wrapping up each interaction in a mutex?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@thedarkone

thedarkone commented Aug 31, 2010

Copy link
Copy Markdown
Contributor Author

None that I know of :(. We'd need Ruby version specific "memoize-friendly" hash implementation (ie. you're fine with plain Hash on MRI/YARV, use some kind of thin wrapper around ConcurrentHashMap on JRuby, something else for future GIL-free Rubinius etc).

Using a global hash on JRuby is basically like playing russian roulette, most of the time you'll probably be fine, however if you are unlucky you might run into a random java.lang.ArrayIndexOutOfBoundsException (survivable) or you'll get with X threads stuck in a infinite loop (kinda sucks for production environment).

Try it for yourself: http://gist.github.com/559673

PS: btw we're in (good?) company with Rails 3 on this one .. https://rails.lighthouseapp.com/projects/8994/tickets/5340

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@josevalim

josevalim commented Nov 15, 2010

Copy link
Copy Markdown
Contributor

So the issue here and in the Rails 3 ticket is that we need to use ConcurrentHashMap in JRuby? Do you think you can provide a small patch? Thanks a lot!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@thedarkone
Avoid using global lazily populated Hashes.
2e34b3e
Replace them with ThreadSafe::Cache.
@thedarkone

thedarkone commented Sep 29, 2013

Copy link
Copy Markdown
Contributor Author

Turning this into a PR.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@thedarkone

thedarkone commented Apr 14, 2014

Copy link
Copy Markdown
Contributor Author

Note to self: I18n::Locale::Fallbacks is also not thread safe.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@radar

radar commented Nov 20, 2016

Copy link
Copy Markdown
Collaborator

@thedarkone Would you be interested in updating this to use something more modern, such as concurrent-ruby? Or whatever you choose, I guess.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@radar radar added this to the 0.9.0 milestone Nov 20, 2016
@radar

radar commented Nov 20, 2016

Copy link
Copy Markdown
Collaborator

Actually, I'll make an attempt at a concurrent-ruby version of this patch now.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@radar radar self-assigned this Nov 20, 2016
@radar radar mentioned this pull request Nov 20, 2016
Thread Safety Fix #352
Merged
@radar

radar commented Nov 20, 2016

Copy link
Copy Markdown
Collaborator

@thedarkone I'd like your feedback on #352 before I merge it, if you have time.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@radar radar modified the milestones: 0.9.0, 0.10.0 Oct 1, 2017
kares added a commit to kares/i18n that referenced this pull request Oct 1, 2017
@kares
test: reproduce possible Hash inconsistency when [] / []= concurrently
7e7a399
... a sometimes reproducer  for ruby-i18n#51 (needs a GIL free Ruby such as JRuby)
@kares kares mentioned this pull request Oct 1, 2017
test: reproduce possible Hash inconsistency when [] / []= concurrently #384
Merged
@lostapathy

lostapathy commented Oct 13, 2017

Copy link
Copy Markdown
Contributor

@thedarkone or @radar can this be closed now that #352 has been merged or are you looking for a PR for something else to complete it?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@radar

radar commented Oct 13, 2017

Copy link
Copy Markdown
Collaborator

Yes this can now be closed.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@radar radar closed this Oct 13, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@radar radar

Labels

None yet

Projects

None yet

Milestone

0.10.0

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@thedarkone @josevalim @radar @lostapathy
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402605 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.