4

I recently upgraded to Rails 5. After upgrading and the fixing the usual things, my application appeared to be running correctly and serving responses.

Even though my test suite passes with 94% coverage, when performing an actual request, the controller crashes after claiming the request was a 200 OK.

It looks like the stack trace does not point to any code in my application, but rather something inside of Actionpack.

Is this a misconfiguration on my part, or a legitimate bug within Rails 5?

Completed 200 OK in 141ms (Views: 2.2ms | ActiveRecord: 124.9ms)

    NoMethodError (undefined method `id' for {}:Hash):

    actionpack (5.0.0.1) lib/action_dispatch/request/session.rb:70:in `id'
    rack (2.0.1) lib/rack/session/abstract/id.rb:341:in `commit_session'
    rack (2.0.1) lib/rack/session/abstract/id.rb:224:in `context'
    rack (2.0.1) lib/rack/session/abstract/id.rb:216:in `call'
    actionpack (5.0.0.1) lib/action_dispatch/middleware/cookies.rb:613:in `call'
    actionpack (5.0.0.1) lib/action_dispatch/middleware/callbacks.rb:38:in `block in call'
    activesupport (5.0.0.1) lib/active_support/callbacks.rb:97:in `__run_callbacks__'
    activesupport (5.0.0.1) lib/active_support/callbacks.rb:750:in `_run_call_callbacks'
    activesupport (5.0.0.1) lib/active_support/callbacks.rb:90:in `run_callbacks'
    actionpack (5.0.0.1) lib/action_dispatch/middleware/callbacks.rb:36:in `call'
    actionpack (5.0.0.1) lib/action_dispatch/middleware/executor.rb:12:in `call'
    actionpack (5.0.0.1) lib/action_dispatch/middleware/remote_ip.rb:79:in `call'
    actionpack (5.0.0.1) lib/action_dispatch/middleware/debug_exceptions.rb:49:in `call'
    actionpack (5.0.0.1) lib/action_dispatch/middleware/show_exceptions.rb:31:in `call'
    railties (5.0.0.1) lib/rails/rack/logger.rb:36:in `call_app'
    railties (5.0.0.1) lib/rails/rack/logger.rb:24:in `block in call'
    activesupport (5.0.0.1) lib/active_support/tagged_logging.rb:70:in `block in tagged'
    activesupport (5.0.0.1) lib/active_support/tagged_logging.rb:26:in `tagged'
    activesupport (5.0.0.1) lib/active_support/tagged_logging.rb:70:in `tagged'
    railties (5.0.0.1) lib/rails/rack/logger.rb:24:in `call'
    actionpack (5.0.0.1) lib/action_dispatch/middleware/request_id.rb:24:in `call'
    rack (2.0.1) lib/rack/method_override.rb:22:in `call'
    rack (2.0.1) lib/rack/runtime.rb:22:in `call'
    activesupport (5.0.0.1) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
    actionpack (5.0.0.1) lib/action_dispatch/middleware/executor.rb:12:in `call'
    actionpack (5.0.0.1) lib/action_dispatch/middleware/static.rb:136:in `call'
    rack-cors (0.4.0) lib/rack/cors.rb:80:in `call'
    rack (2.0.1) lib/rack/sendfile.rb:111:in `call'
    railties (5.0.0.1) lib/rails/engine.rb:522:in `call'
    thin (1.7.0) lib/thin/connection.rb:86:in `block in pre_process'
    thin (1.7.0) lib/thin/connection.rb:84:in `catch'
    thin (1.7.0) lib/thin/connection.rb:84:in `pre_process'
    thin (1.7.0) lib/thin/connection.rb:53:in `process'
    thin (1.7.0) lib/thin/connection.rb:39:in `receive_data'
    eventmachine (1.2.1) lib/eventmachine.rb:194:in `run_machine'
    eventmachine (1.2.1) lib/eventmachine.rb:194:in `run'
    thin (1.7.0) lib/thin/backends/base.rb:73:in `start'
    thin (1.7.0) lib/thin/server.rb:162:in `start'
    rack (2.0.1) lib/rack/handler/thin.rb:22:in `run'
    rack (2.0.1) lib/rack/server.rb:296:in `start'
    railties (5.0.0.1) lib/rails/commands/server.rb:79:in `start'
    railties (5.0.0.1) lib/rails/commands/commands_tasks.rb:90:in `block in server'
    railties (5.0.0.1) lib/rails/commands/commands_tasks.rb:85:in `tap'
    railties (5.0.0.1) lib/rails/commands/commands_tasks.rb:85:in `server'
    railties (5.0.0.1) lib/rails/commands/commands_tasks.rb:49:in `run_command!'
    railties (5.0.0.1) lib/rails/commands.rb:18:in `<top (required)>'
    bin/rails:4:in `require'
    bin/rails:4:in `<main>'
Rick
  • 8,366
  • 8
  • 47
  • 76
  • Is this in testing or serving a page in the browser? Do you have an active session that you can try deleting? (maybe some old data there?) –  Nov 29 '16 at 02:45
  • Serving an actual JSON document. I disabled cookies and sessions in Rails 4 (pre upgrade) since it is an API. – Rick Nov 29 '16 at 04:56
  • Is it possible that part of your middleware stack is trying to do something with the session, and it fails because it's disabled? –  Nov 29 '16 at 08:34
  • I was suspicious of that, but I don't see any custom middleware in the stack trace. Just a bunch of Rails stuff. – Rick Nov 29 '16 at 14:24
  • Can you open rails console and tell use the value for ActionDispatch::Request::Session::ENV_SESSION_OPTIONS_KEY and the Rack env for the request. If you don't have the env output you can just log request.env from the controller, I think. –  Nov 29 '16 at 15:15
  • I just found the problem. Will update question. – Rick Nov 29 '16 at 15:50
  • 2
    Cool you should add it as an answer. –  Nov 29 '16 at 15:57

1 Answers1

1

I found the issue. In the Rails 4 days of the app, I set request.session_options to {}. It appears that it is no longer a hash in Rails 5. I now use reset_session in place of request.session_options = {}.

Community
  • 1
  • 1
Rick
  • 8,366
  • 8
  • 47
  • 76