#18 √ resolved
Simon Rozet

Reloading bug in development

Reported by Simon Rozet | May 6th, 2008 @ 11:46 AM | in 0.3.0 Sammy

When you hit sinatra too fast, it fails at reloading, resulting in the fellowing error :

[[[

Tue May 06 20:37:43 +0200 2008: Read error: #

/home/simon/code/git-wiki/vendor/sinatra/lib/sinatra.rb:935:in `load'

/home/simon/code/git-wiki/vendor/sinatra/lib/sinatra.rb:935:in `reload!'

/home/simon/code/git-wiki/vendor/sinatra/lib/sinatra.rb:953:in `call'

/home/simon/code/git-wiki/vendor/sinatra/vendor/rack/lib/rack/commonlogger.rb:20:in `_call'

/home/simon/code/git-wiki/vendor/sinatra/vendor/rack/lib/rack/commonlogger.rb:13:in `call'

/home/simon/code/git-wiki/vendor/sinatra/vendor/rack/lib/rack/handler/mongrel.rb:59:in `process'

/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:159:in `process_client'

/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:158:in `each'

/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:158:in `process_client'

/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:285:in `run'

/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:285:in `initialize'

/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:285:in `new'

/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:285:in `run'

/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:268:in `initialize'

/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:268:in `new'

/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:268:in `run'

/home/simon/code/git-wiki/vendor/sinatra/vendor/rack/lib/rack/handler/mongrel.rb:32:in `run'

/home/simon/code/git-wiki/vendor/sinatra/lib/sinatra.rb:152:in `run'

/home/simon/code/git-wiki/vendor/sinatra/lib/sinatra.rb:1288

]]]

That's (IMO) definitely not a big deal and I'll be tempted to say "WONTFIX!" but still... it took me a while to figure out why the hell that 'edit in place' was causing Sinatra to fail.

Comments and changes to this ticket

  • Blake Mizerany

    Blake Mizerany May 6th, 2008 @ 05:05 PM

    • → State changed from “new” to “hold”

    I've seen this before too due to my mini-OCD of rapid-fire-cmd+R when thinking. I'm sure it has to do with the forced Kernel.load on each request. Rails/Merb/others use a thread-based reloader that pulls things into memory at an interval. I've contemplated moving to this.

    There is one build into Rack. If you have a moment and want to look into how this could replace Sinatra's current reloader I'd be grateful.

  • Simon Rozet

    Simon Rozet May 7th, 2008 @ 08:10 AM

    Sure, I'll look into it ASAP.

  • Simon Rozet

    Simon Rozet May 9th, 2008 @ 07:25 AM

    OK, so it's basically only a matter of adding :

    app = Rack::Reloader.new(app) if development?

    in Sinatra.build_application.

    But there is a problem. Current reload! method do three things :

    • clearables.each(&:clear)
    • load_default_events! (events[:get] << Static.new)
    • Environment.setup!

    I can't figure out how to make Rack::Reloader do that except by monkey-patching it. Do you think patching Rack::Reloader.new so that it accepts two proc which would be executed before and after reloading would be a good idea?

  • Simon Rozet

    Simon Rozet May 9th, 2008 @ 09:16 AM

    OK, so it's basically only a matter of adding :

    It was was a bit presumptuous actually. Sorry for trying to go too fast.

    I pushed my branch to github so I am talking about code (as opposed to wind) It is actually totally useless: it only reloads the required files and not the actual application... Also, if you hit the server too much/fast, it'll fall off and acts like if there was no routes defined (which I don't understand why)

    So, IMO we need to use some custom reloading code because Rack::Reloader doesn't really fits our needs.

    What do you think?

    BTW, I wonder which communication way do you prefer? Is it OK to be noisy on the lighthouse?

  • Blake Mizerany

    Blake Mizerany May 9th, 2008 @ 12:08 PM

    Be noisy. Only people who signed up for the messages will get it.

    I'm not sure where to go with this yet. Rack::Reloader isn't the answer as far as I can tell.

    I think the clearables will go away soon and at that point we can look at this again.

    If you hitting your app that hard then you should probably be in production mode.

  • Ryan Tomayko

    Ryan Tomayko May 23rd, 2008 @ 09:39 PM

    I think I may have figured this one out. Can you guys see if the following works as a fix:

    http://github.com/rtomayko/sinat...

    I'm basically wrapping the reload (reloading is impossible to make thread safe) and the middleware pipeline in the mutex lock. And the mutex lock is always used in development.

  • Ryan Tomayko

    Ryan Tomayko September 7th, 2008 @ 06:39 PM

    • → Tag changed from “” to “bug”
    • → State changed from “hold” to “resolved”

    I'm almost positive I resolved this. If anyone can recreate from my master / 0.3, we'll reopen.

Please Login or create a free account to add a new comment.

You can update this ticket by sending an email to from your email client. (help)

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

People watching this ticket

Tags