Search code examples
ruby-on-railsconsoleauthlogic

Authlogic save causing 502 Bad Gateway error, Illegal Instruction in Rails console


I recently set up a new app server (Ruby 1.8.7 REE, Rails 2.3.8, Passenger 3.0.9, Nginx 1.0.6) behind a proxy and am encountering some strange behavior. When posting to /login on this app server alone, I get a 502 Bad Gateway error. This does not happen on the other app server, and both are set up identically. I've narrowed the problem down to a specific line of code - the saving of an Authlogic session. When I comment out these lines (specifically the save call):

@user_session = UserSession.new(params[:user_session])
if @user_session.save
...

the 502 error no longer occurs. Likewise, when I test these commands in the console, I get an Illegal Instruction response and the console crashes:

>> Authlogic::Session::Base.controller = Authlogic::ControllerAdapters::RailsAdapter.new(self)
>> @user_session = UserSession.new({"password"=>"password", "remember_me"=>"0", "login"=>"myuser"})
>> @user_session.save
Illegal instruction

Testing this on the other app server works just fine (console does not crash with Illegal Instruction result).

Any idea where to begin troubleshooting this? I see nothing of value in either the Rails logs or the Nginx logs.

Thanks.

Edit

The Illegal Instruction is occurring during a system call to digest.rb. The same thing happens whether I use the Ubuntu Ruby Enterprise Edition package or whether I compile it myself:

stat("/opt/ruby-enterprise-1.8.7-2011.12/lib/ruby/1.8/digest.rb", {st_mode=S_IFREG|0644, st_size=1145, ...}) = 0
open("/opt/ruby-enterprise-1.8.7-2011.12/lib/ruby/1.8/digest.rb", O_RDONLY) = 15
fstat(15, {st_mode=S_IFREG|0644, st_size=1145, ...}) = 0
close(15)                               = 0
--- SIGILL (Illegal instruction) @ 0 (0) ---

Solution

  • This sounds like it's related to Ruby 1.9 Ramaze App Failing with “Illegal instruction”.

    Jörg W Mittag said:

    "Illegal instruction" is usually an error message from the CPU meaning some piece of binary code you tried to run contained an instruction that is not implemented on that particular CPU.

    This can have multiple reasons:

    • The binary was compiled with optimization settings for the wrong CPU. The CPU vendors add new instructions all the time, if the compiler optimizes for a CPU that is newer than the one you have, it might have emitted an instruction that your CPU doesn't understand.
    • The compiler is broken.
    • The binary is corrupted.
    • The code you are compiling contains assembly code or intrinsics containing instructions that your CPU doesn't have.

    The original question submitter Phil Kulak replied that he had found a stack overflow causing the error.