Defect #18930

session_expiration fails to find active user to set localization for

Added by Josh Miller over 7 years ago. Updated almost 7 years ago.

Status:ClosedStart date:
Priority:NormalDue date:
Assignee:-% Done:

0%

Category:I18n
Target version:-
Resolution:Invalid Affected version:2.6.1

Description

Redmine 2.6.1, mysql, amazon linux.

When a session has expired and the user attempts to use Redmine, a 500 error is returned as the session_expiration method is unable to find an active user to set the localization for.

Problem area:

  def session_expiration
    if session[:user_id]
      if session_expired? && !try_to_autologin
        set_localization(User.active.find_by_id(session[:user_id]))
        reset_session
        flash[:error] = l(:error_session_expired)
        redirect_to signin_url
      else
        session[:atime] = Time.now.utc.to_i
      end
    end
  end

With the error:

Started GET "/" for x.x.x.x at 2015-01-21 23:37:33 +0000
Processing by WelcomeController#index as HTML
  User Load (0.7ms) SELECT `users`.* FROM `users` WHERE `users`.`type` IN ('User', 'AnonymousUser') AND `users`.`status` = 1 AND `use
rs`.`id` = 12 LIMIT 1
Completed 500 Internal Server Error in 2.1ms

ArgumentError (wrong number of arguments (1 for 0)):
  app/controllers/application_controller.rb:65:in `session_expiration'

If a reset_session is called before set_localization, and set_localization is without parameters, the correct behavior occurs, where the user is redirected toa login screen and no 500 error occurs.

  def session_expiration
    if session[:user_id]
      if session_expired? && !try_to_autologin
        reset_session
        set_localization
        flash[:error] = l(:error_session_expired)
        redirect_to signin_url
      else
        session[:atime] = Time.now.utc.to_i
      end
    end
  end

History

#1 Updated by Jean-Philippe Lang over 7 years ago

  • Status changed from New to Closed
  • Resolution set to Invalid

The problem is not that the user cannot be found. This exception ArgumentError (wrong number of arguments (1 for 0)) should not be raised as ApplicationController#set_localization now accepts an optional argument. Make sure your code was properly updated:
source:tags/2.6.1/app/controllers/application_controller.rb#L214

Please reopen if I'm missing something.

#2 Updated by Josh Miller over 7 years ago

  • Status changed from Closed to Reopened

I've confirmed that I have the latest 2.6.1 code by downloading a fresh tgz, extracting, and running a diff on all files, especially application_controller.rb.

def set_localization(user=User.current)

Could the issue be that the User.current call returns nil due to an expired session which results in the argument error?

#3 Updated by Chris Fields over 7 years ago

We are also seeing the same issue on our private Redmine instance. A simple restart of the browser seems to fix the problem in most cases.

EDIT: Using:

Environment:
  Redmine version                2.6.1.stable
  Ruby version                   2.1.5-p273 (2014-11-13) [x86_64-linux]
  Rails version                  3.2.21
  Environment                    production
  Database adapter               Mysql2
SCM:
  Git                            1.7.1
  Filesystem                     
Redmine plugins:
  due_date_reminder              0.3.2
  redmine_cms                    0.0.3
  redmine_contacts               3.4.4
  redmine_contacts_helpdesk      2.3.0
  redmine_contacts_invoices      3.2.3
  redmine_favorite_projects      1.0.1
  redmine_questions              0.0.5

#4 Updated by Jean-Philippe Lang over 7 years ago

  • Status changed from Reopened to Closed

Josh Miller wrote:

Could the issue be that the User.current call returns nil due to an expired session which results in the argument error?

User.current returning nil would not trigger a wrong number of arguments (1 for 0) error.

We are also seeing the same issue on our private Redmine instance. A simple restart of the browser seems to fix the problem in most cases.

You're using the redmine_cms plugin. After a quick check, this plugin patches ApplicationController#set_localization without accepting any arguments (see redmine_cms\lib\redmine_cms\patches\application_controller_patch.rb). This is the cause of the ArgumentError here.

#5 Updated by Chris Fields over 7 years ago

Thanks Jean-Phillipe. I'll notify the RedmineCRM developers of this.

#6 Updated by Andrew Kohlsmith almost 7 years ago

Chris Fields wrote:

Thanks Jean-Phillipe. I'll notify the RedmineCRM developers of this.

I'm also experiencing this problem (Redmine 2.6.6, RedmineCMS 0.0.3). I haven't seen anything on their forum, did they supply you with an interim fix?

Also available in: Atom PDF