Rails + jquery : ERROR Errno::ECONNRESET: Connection reset by peer

1.9k Views Asked by At

I have a problem when I send an AJAX request with jquery in my Rails 4 app (ruby 2.0).

The error is:

ERROR Errno::ECONNRESET: Connection reset by peer

JS:

$("#user_main_filter_all").click(function() 
{
    $("#spinner").show();
$.ajax({
        dataType: "json",
  cache: false,
        url: '/finder/main_filter_changed/all',
  timeout: 5000,
        beforeSend : function(xhr) { xhr.setRequestHeader("Accept", "application/json") },
  error: function(XMLHttpRequest, errorTextStatus, error) { alert("Failed to submit : "+ errorTextStatus+" ;"+error); },
  success: function(data) 
        {                    
            $("#user_main_filter_all").css("background-color","#000000");
            $("#user_main_filter_stored").css("background-color","transparent");

            $("#spinner").hide();

            refresh_user_data();
    }
});
});

Ruby (method called):

  def main_filter_changed
    session[:user_page] = nil

    if !params[:id].blank?
      session[:user_main_filter] = params[:id]
    else
      session[:user_main_filter] = 'all'
    end

    respond_to do |format|
      format.json  { render :json => nil }     
    end

  end

The method is called and just after, I have in my logs:

Processing by FinderController#main_filter_changed as JSON
  Parameters: {"_"=>"1387190059468", "id"=>"all"}
Completed 200 OK in 3ms (Views: 0.2ms | ActiveRecord: 0.5ms)
[2013-12-16 11:34:20] ERROR Errno::ECONNRESET: Connection reset by peer

    /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/webrick/httpserver.rb:80:in `eof?'
    /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/webrick/httpserver.rb:80:in `run'
    /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/webrick/server.rb:295:in `block in start_thread'

My first though was a problem with protect_from_forgery and csrf_token... but I just tested and commented the line protect_from_forgery and I have the same behaviour.

So the server error gives the javascript alert:

error: function(XMLHttpRequest, errorTextStatus, error) { alert("Failed to submit : "+ errorTextStatus+" ;"+error); },

is called the the alert box shown (but not the errorTextStatus).

0

There are 0 best solutions below