500 error when executing lots of sqls.

dlhhyct

Active Member
#1
  • under lsws and ruby lsapi, I often get "The size of dynamic response header is over the limit." warning msg when page or controller method contains large amount of sql calls. lsws aborts the request, and lsws returns 500 server error in browser.
  • although all sqls are executed, and controller method completes successfully, browser just returns 500 error anyway.
  • In admin GUI, After I change tuning/Max Dynamic Response Header Size (bytes) to 8192, instead of 500 error, browser ask me to download the page, I guess for debugging purpose, file (1-2 kb) I download starts with one sql statement and follows with binary stuff. Download only happens in rails development mode, production mode always returns 500 error regardless header size.
  • Same code works under webrick.
  • I know header size is for security/ddos reasons, why does it go off when I do lots of sqls?

how do I avoid this error when I have to do lots of sql calls?

test code below, try raise or lower the number to see different behaviors.
Code:
class TestController < ApplicationController
  def index
    70.times{|i|   
      begin
        logger.info(i)
        user = User.find(i)
      rescue Exception => err   # rails throw err if no user found
        logger.error(err)
      end
    }
  end
end
 

dlhhyct

Active Member
#2
hold on

spoke too soon, I create a whole new app, and was unable to reproduce 500 error, i guess cause is somewhere else in my current app. :(

please disregard my previous post.
 

mistwang

LiteSpeed Staff
#3
Maybe your rails app uses a lot of memory for those SQL, try increasing the "memory limit" under "Rails" tab, see if it helps or not.

You should be able to find some clues for this problem in lsws/logs/stderr.log, lsws/logs/error.log as well as Rails' log files.
 

dlhhyct

Active Member
#4
solved

in my code, i had lots of puts statements to debug, and i even overwrite logger.debug in model classes, because debug msg wasn't showing somehow before. after i remove all of these puts. problem went away.

Code:
def logger.debug(msg)
  puts msg
end
I guess when lots of sql is being called, all these puts accumulates and exceed header limit.
 
Top