sinatra / rack-protection

NOTE: This project has been merged upstream to sinatra/sinatra
https://github.com/sinatra/sinatra/tree/master/rack-protection
818 stars 58 forks source link

Don't autoload? #45

Closed charlie closed 8 years ago

charlie commented 11 years ago

http://www.ruby-forum.com/topic/3036681

Posted by Yukihiro Matsumoto (Guest) on 2011-11-19 08:12  
Hi,

Today, I talked with NaHi about enhancing const_missing to enable
autoload-like feature with nested modules.  But autoload itself has
fundamental flaw under multi-thread environment.  I should have remove
autoload when I added threads to the language (threads came a few
months after autoload).

So I hereby declare the future deprecation of autoload.  Ruby will
keep autoload for a while, since 2.0 should keep compatibility to 1.9.
But you don't expect it will survive further future, e.g. 3.0.

I strongly discourage the use of autoload in any standard libraries.

              matz.
rkh commented 11 years ago

Development on Ruby 3.0 has not yet started. Matz is quick at changing his opinion (see Module#prepend).

I don't see a threading issue, tbh, as the autoloads should be triggered at load time.

charlie commented 11 years ago

I'm not sure what "should be triggered at load time" means. The docs about Kernel#autoload say:

Registers filename to be loaded (using Kernel::require) the first time that module (which may be a String or a symbol) is accessed.

Last I heard, Kernel#require was not threadsafe. Has that changed? If not, I still question whether deferred non-threadsafe lazy-loading is correct for a core library like rack-protection, whether or not development on Ruby 3.0 has started.

rkh commented 11 years ago

But you won't lazy load anywhere but the main thread.

charlie commented 11 years ago

I guess I don't understand something about autoload/require. There is some guarantee that 2 threads can't/won't call require at the same time?

rkh commented 11 years ago

No. But that does not have anything to do with autoload.

rkh commented 11 years ago

JRuby and Ruby 2.0 autoload is thread-safe and Rubinius autoload is going to be.

joshjordan commented 11 years ago

@rkh can you cite a source for that (particularly Ruby 2)? I've been trying to chase this answer down and don't see evidence for that, especially given what Matz said in the post that started this thread.

kriansa commented 11 years ago

I'm also curious about it. Since I started coding with ruby, I see people talking about the autoload not being thread-safe, but I could'nt find a workaround or a official statement about that.

bf4 commented 10 years ago

@joshjordan see http://bugs.ruby-lang.org/projects/ruby-trunk/repository/revisions/33078 (linked in the headius/thread_safe) issue

rkh commented 10 years ago

<3

zzak commented 8 years ago

I think its safe to close this issue, autoload should be threadsafe so we won't change the design of rack-protection for this.