title: Ruby IO Error, not opened for reading
body: <p>Using OmniAuth for Facebook with Sinatra and Ruby 1.9.3. Getting the IO not opened for reading error during the latter stage of the auth process. Haven't seen much else about this online. If you require any more info please let me know.  </p>
  
  <p>Failing on the MultiJson line:</p>
  
  <pre><code>get '/auth/failure' do
  content_type 'application/json'
  MultiJson.encode(request.env)
  end
  </code></pre>
  
  <p>Error:</p>
  
  <p>IOError at /auth/facebook/callback
  not opened for reading
  file: encoding.rb location: each line: 256</p>
  
  <p>Detailed error log:</p>
  
  <pre><code>== Sinatra/1.4.4 has taken the stage on 4567 for development with backup from Thin
  Thin web server (v1.6.1 codename Death Proof)
  Maximum connections set to 1024
  Listening on localhost:4567, CTRL+C to stop
          SECURITY WARNING: No secret option provided to Rack::Session::Cookie.
          This poses a security threat. It is strongly recommended that you
          provide a secret to prevent exploits that may be possible from crafted
          cookies. This will not be supported in future versions of Rack, and
          future versions will even invalidate your existing user cookies.
  
          Called from: /Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/rack-1.5.2/lib/rack/builder.rb:86:in `new'.
  
  127.0.0.1 - - [08/Dec/2013 18:34:03] "GET / HTTP/1.1" 302 - 0.0025
  I, [2013-12-08T18:34:03.828713 #927]  INFO -- omniauth: (facebook) Request phase initiated.
  127.0.0.1 - - [08/Dec/2013 18:34:03] "GET /auth/facebook HTTP/1.1" 302 203 0.0049
  I, [2013-12-08T18:34:04.278981 #927]  INFO -- omniauth: (facebook) Callback phase initiated.
  IOError - not opened for reading:
      /Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/activesupport-4.0.1/lib/active_support/json/encoding.rb:256:in `each'
      /Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/activesupport-4.0.1/lib/active_support/json/encoding.rb:256:in `to_a'
      /Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/activesupport-4.0.1/lib/active_support/json/encoding.rb:256:in `as_json'
      /Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/activesupport-4.0.1/lib/active_support/json/encoding.rb:58:in `block in as_json'
      /Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/activesupport-4.0.1/lib/active_support/json/encoding.rb:81:in `check_for_circular_references'
      /Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/activesupport-4.0.1/lib/active_support/json/encoding.rb:57:in `as_json'
      /Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/activesupport-4.0.1/lib/active_support/json/encoding.rb:296:in `block in as_json'
      /Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/activesupport-4.0.1/lib/active_support/json/encoding.rb:296:in `each'
      /Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/activesupport-4.0.1/lib/active_support/json/encoding.rb:296:in `map'
      /Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/activesupport-4.0.1/lib/active_support/json/encoding.rb:296:in `as_json'
      /Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/activesupport-4.0.1/lib/active_support/json/encoding.rb:50:in `block in encode'
      /Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/activesupport-4.0.1/lib/active_support/json/encoding.rb:81:in `check_for_circular_references'
      /Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/activesupport-4.0.1/lib/active_support/json/encoding.rb:49:in `encode'
      /Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/activesupport-4.0.1/lib/active_support/json/encoding.rb:34:in `encode'
      /Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/activesupport-4.0.1/lib/active_support/core_ext/object/to_json.rb:16:in `to_json'
      /Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/multi_json-1.8.2/lib/multi_json/adapters/json_common.rb:21:in `dump'
      /Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/multi_json-1.8.2/lib/multi_json/adapter.rb:24:in `dump'
      /Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/multi_json-1.8.2/lib/multi_json.rb:137:in `dump'
      app.rb:87:in `block in &lt;main&gt;'
      /Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/sinatra-1.4.4/lib/sinatra/base.rb:1593:in `call'
      /Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/sinatra-1.4.4/lib/sinatra/base.rb:1593:in `block in compile!'
      /Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/sinatra-1.4.4/lib/sinatra/base.rb:957:in `[]'
      /Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/sinatra-1.4.4/lib/sinatra/base.rb:957:in `block (3 levels) in route!'
      /Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/sinatra-1.4.4/lib/sinatra/base.rb:976:in `route_eval'
      /Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/sinatra-1.4.4/lib/sinatra/base.rb:957:in `block (2 levels) in route!'
      /Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/sinatra-1.4.4/lib/sinatra/base.rb:997:in `block in process_route'
      /Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/sinatra-1.4.4/lib/sinatra/base.rb:995:in `catch'
      /Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/sinatra-1.4.4/lib/sinatra/base.rb:995:in `process_route'
      /Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/sinatra-1.4.4/lib/sinatra/base.rb:955:in `block in route!'
      /Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/sinatra-1.4.4/lib/sinatra/base.rb:954:in `each'
      /Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/sinatra-1.4.4/lib/sinatra/base.rb:954:in `route!'
      /Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/sinatra-1.4.4/lib/sinatra/base.rb:1067:in `block in dispatch!'
      /Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/sinatra-1.4.4/lib/sinatra/base.rb:1049:in `block in invoke'
      /Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/sinatra-1.4.4/lib/sinatra/base.rb:1049:in `catch'
      /Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/sinatra-1.4.4/lib/sinatra/base.rb:1049:in `invoke'
      /Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/sinatra-1.4.4/lib/sinatra/base.rb:1064:in `dispatch!'
      /Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/sinatra-1.4.4/lib/sinatra/base.rb:889:in `block in call!'
      /Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/sinatra-1.4.4/lib/sinatra/base.rb:1049:in `block in invoke'
      /Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/sinatra-1.4.4/lib/sinatra/base.rb:1049:in `catch'
      /Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/sinatra-1.4.4/lib/sinatra/base.rb:1049:in `invoke'
      /Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/sinatra-1.4.4/lib/sinatra/base.rb:889:in `call!'
      /Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/sinatra-1.4.4/lib/sinatra/base.rb:877:in `call'
      /Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/omniauth-1.1.4/lib/omniauth/strategy.rb:401:in `call_app!'
      /Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/omniauth-1.1.4/lib/omniauth/strategy.rb:363:in `callback_phase'
      /Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/omniauth-oauth2-1.0.3/lib/omniauth/strategies/oauth2.rb:65:in `callback_phase'
      /Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/omniauth-1.1.4/lib/omniauth/strategy.rb:226:in `callback_call'
      /Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/omniauth-1.1.4/lib/omniauth/strategy.rb:182:in `call!'
      /Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/omniauth-1.1.4/lib/omniauth/strategy.rb:164:in `call'
      /Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/omniauth-1.1.4/lib/omniauth/builder.rb:49:in `call'
      /Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/rack-1.5.2/lib/rack/session/abstract/id.rb:225:in `context'
      /Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/rack-1.5.2/lib/rack/session/abstract/id.rb:220:in `call'
      /Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/rack-protection-1.5.1/lib/rack/protection/xss_header.rb:18:in `call'
      /Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/rack-protection-1.5.1/lib/rack/protection/path_traversal.rb:16:in `call'
      /Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/rack-protection-1.5.1/lib/rack/protection/json_csrf.rb:18:in `call'
      /Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/rack-protection-1.5.1/lib/rack/protection/base.rb:50:in `call'
      /Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/rack-protection-1.5.1/lib/rack/protection/base.rb:50:in `call'
      /Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/rack-1.5.2/lib/rack/logger.rb:15:in `call'
      /Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/rack-1.5.2/lib/rack/commonlogger.rb:33:in `call'
      /Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/sinatra-1.4.4/lib/sinatra/base.rb:217:in `call'
      /Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/sinatra-1.4.4/lib/sinatra/base.rb:210:in `call'
      /Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/rack-1.5.2/lib/rack/head.rb:11:in `call'
      /Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/rack-1.5.2/lib/rack/methodoverride.rb:21:in `call'
      /Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/sinatra-1.4.4/lib/sinatra/show_exceptions.rb:21:in `call'
      /Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/sinatra-1.4.4/lib/sinatra/base.rb:180:in `call'
      /Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/sinatra-1.4.4/lib/sinatra/base.rb:2004:in `call'
      /Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/sinatra-1.4.4/lib/sinatra/base.rb:1469:in `block in call'
      /Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/sinatra-1.4.4/lib/sinatra/base.rb:1778:in `synchronize'
      /Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/sinatra-1.4.4/lib/sinatra/base.rb:1469:in `call'
      /Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/thin-1.6.1/lib/thin/connection.rb:82:in `block in pre_process'
      /Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/thin-1.6.1/lib/thin/connection.rb:80:in `catch'
      /Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/thin-1.6.1/lib/thin/connection.rb:80:in `pre_process'
      /Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/eventmachine-1.0.3/lib/eventmachine.rb:1037:in `call'
      /Users/philhudson/.rvm/gems/ruby-1.9.3-p448/gems/eventmachine-1.0.3/lib/eventmachine.rb:1037:in `block in spawn_threadpool'
  </code></pre>