quiet_assets icon indicating copy to clipboard operation
quiet_assets copied to clipboard

README to highlight does not work in threadsafe mode

Open seantanly opened this issue 13 years ago • 13 comments

I believe the readme should include a note on quiet_assets being not threadsafe, and should turn off quiet_assets through config.quiet_assets = false.

It would save users of this gem from some frustration when they are using it in threadsafe mode, and their logs starts to disappear randomly, development mode or not.

Due how quiet_assets work, which is toggling the Rails.logger.level, based on the current implementation of the default Rails logger (3.2.11), it is probably impossible to make it work in threadsafe mode.

Further technical discussion on yell regarding this topic. https://github.com/rudionrails/yell/issues/4

Thank you for this convenient gem.

seantanly avatar Jan 10 '13 15:01 seantanly

@seantan Thanks for the info I'll take a look!

route avatar Jan 17 '13 07:01 route

@route You're welcomed. More specifically on the same yell thread, it is this comment, https://github.com/rudionrails/yell/issues/4#issuecomment-10054798

seantanly avatar Jan 17 '13 11:01 seantanly

I have an idea about this mistake. @seantan can you participate in it? I've created a branch using_middleware could you run your application and check it works properly?

route avatar Jan 21 '13 08:01 route

Never mind my previous comment, seems like some parts won't work for rails 4

route avatar Jan 21 '13 10:01 route

@route looks like an interesting idea and it seems to work for me on Rails 3.2.11 though.

seantanly avatar Jan 21 '13 15:01 seantanly

Yes it works for 3.2 but there are diffs in logger implementation between rails versions. Thinking about realization now...

route avatar Jan 21 '13 15:01 route

With a blank new standard MRI rails 4 app. Add puma and quiet_assets to the Gemfile. Set rails config:

config.allow_concurrency = true

Start clicking around, you loose almost all the non-asset output.

pierre-pretorius avatar Mar 28 '14 08:03 pierre-pretorius

@pierre-pretorius have you tried to use QA from master branch?

route avatar Mar 28 '14 08:03 route

Just tried it now: Using quiet_assets (1.0.2) from git://github.com/evrone/quiet_assets.git (at master). Still get the same problem.

pierre-pretorius avatar Mar 28 '14 08:03 pierre-pretorius

Ok got it, will take a look. Maybe @dima-exe has something to say?

route avatar Mar 28 '14 08:03 route

Thanks. It seems like this gem is the only way to address asset logging. Rails config doesn't take everything away. Anyone doing Rails::Live/websockets development probably needs multi threading in dev mode. Would be great if this gem could be threadsafe.

pierre-pretorius avatar Mar 28 '14 08:03 pierre-pretorius

Any progress on this issue? To set a global variable that is scoped per thread, use: Thread.current['local_var'] = some_var

http://bonamin.org/blog/2012/03/06/thread-safe-global-variables-in-ruby/

pierre-pretorius avatar Apr 09 '14 15:04 pierre-pretorius

Using a Thread local variable won't solve this problem. This is a race condition on the Rails.logger.level object. To solve it a mutex needs to be used around the entire method body, which is probably undesirable for many reasons.

Imagine the following scenario with a rails app running on log level info

Thread 1: Request arrives
Thread 1: store Rails.logger.level into method local copy of env hash(saves 'info')
Thread 2: Request arrives
Thread 1: set Rails.logger.level = error
Thread 2: store Rails.logger.level into method local copy of env hash(saves 'error')
Thread 1: allow app to process request
Thread 1: set Rails.logger.level = 'info', the value saved earlier in this thread
Thread 2: allow app to process request
Thread 2: set Rails.logger.level = 'error', the value saved earlier in this thread

Even if you replaced the location where you are storing the current logging level with a thread safe variable you can not prevent another thread from setting the Rails.logger.level to 'error'.

mchristen avatar Jun 02 '15 03:06 mchristen