font_assets icon indicating copy to clipboard operation
font_assets copied to clipboard

This Gem is not thread safe

Open jgwmaxwell opened this issue 10 years ago • 5 comments

This gem currently uses a shared ivar which will be overwritten by competing requests in threaded web servers - this PR fixes that by duping and calling out to a private method to eliminate sharing state between threads.

jgwmaxwell avatar Mar 25 '14 18:03 jgwmaxwell

Is this how other middleware's handle this issue? It looks like it will produce a thread-safe result but is it also creating too many objects by duping every request?

ericallam avatar Mar 25 '14 21:03 ericallam

Hey, there's basically two choices on this front: you've either go to work without using variables that can be mutated, or instantiate a new handler for each request. Whether there is a standard way to do it is a complex question I think, mainly based around how complex what the middleware does is.

The solution here is to possibly pivot around whether this middleware is interested or not - if it isn't a request that is applicable then just @app.call otherwise dup and process, might be a nice compromise. Ultimately though, thread safety can only be ignored here if one is running Unicorn, which is an increasingly small part of the ecosystem.

jgwmaxwell avatar Mar 25 '14 22:03 jgwmaxwell

The solution here is to possibly pivot around whether this middleware is interested or not - if it isn't a request that is applicable then just @app.call otherwise dup and process, might be a nice compromise.

I like that idea. Could you update the pull request to do accomplish this? Also, make sure you add specs for anything that is changing, and if you are up for it adding specs to test the thread-safety.

ericallam avatar Mar 25 '14 22:03 ericallam

:+1:

acrogenesis avatar Jan 06 '15 18:01 acrogenesis

any news regarding this?

PericlesTheo avatar Dec 10 '15 10:12 PericlesTheo