# FastCGI - incomplete headers + 500 error

**URL:** <https://www.ruby-forum.com/t/fastcgi-incomplete-headers-500-error/49493>\
**Category:** Rails\
**Created:** [December 5, 2005, 11:20am UTC](https://www.ruby-forum.com/t/fastcgi-incomplete-headers-500-error/49493 "2005-12-05T11:20:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![garychlin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/7feea3/32.png) [@garychlin](https://www.ruby-forum.com/u/garychlin)\
**Post date:** [December 5, 2005, 11:20am UTC](https://www.ruby-forum.com/t/fastcgi-incomplete-headers-500-error/49493/1 "2005-12-05T11:20:48Z")

</div>

Hi,

I know this topic has been discussed before, but I tried every solutions  
still cannot solve it.

The thing is, I run my rails app in dreamhost, with FastCGI.  
(rails-0.14.3+  
ruby-fcgi-0.8.6 + fcgi-2.4.0)  
I can start my app, but I keep hitting 500 error randomly. That is, for  
the  
same page, I will get 500 sometimes, but ok after reload.

This is what I got from fastcgi.crash.log

[…] asked to terminate immediately  
[…] terminated by explicit exit exit

And in apache log

… FastCGI: incomplete headers (0 bytes) received from server  
“/home/…/public/dispatch.fcgi”

I search all the forum on the web, and these are what I have done.

1. change public/.htaccess to RewriteRule ^(.\*)$ dispatch.fcgi [QSA,L]
2. chmod 755 for dispatch.fcgi, and log directory
3. check the ruby path (#!/path/local/bin/ruby) in dispatch.fcgi
4. make sure dispatch.fcgi is not dos format (run dos2unix)

But it still doesn’t work after I have done all of these.

Then I tried these

1. 

[http://convergentarts.com/articles/2005/08/16/new-fcgi\_handler-rb-cuts-500-errors-or-so](http://convergentarts.com/articles/2005/08/16/new-fcgi_handler-rb-cuts-500-errors-or-so)  
copy the lastest  
fcgi\_handler.rb[http://dev.rubyonrails.org/svn/rails/trunk/railties/lib/fcgi\_handler.rb](http://dev.rubyonrails.org/svn/rails/trunk/railties/lib/fcgi_handler.rb)to  
lib  
but actually it’s unnecessary because that file is exactly the same  
as I  
have in rails 0.14-3  
- still doesn’t work

1. [http://forum.textdrive.com/viewtopic.php?id=2972](http://forum.textdrive.com/viewtopic.php?id=2972)  
according to this, fcgi has some problem from gem, so I uninstall  
fcgi  
gem, and make ruby-fcgi-0.8.6  
from source.

2. downgrade rails to 0.13.1, no help

3. try to run dispatch.fcgi manually

That really drives me crazy.  
I don’t know what else I can try, please give me advise if you think of  
any.  
Thanks!

Gary

---

<div class="post-metadata">

**Author:** ![garychlin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/7feea3/32.png) [@garychlin](https://www.ruby-forum.com/u/garychlin)\
**Post date:** [December 5, 2005, 8:45pm UTC](https://www.ruby-forum.com/t/fastcgi-incomplete-headers-500-error/49493/2 "2005-12-05T20:45:50Z")

</div>

Finally, I use a work-around solution before anybody can tell me a  
better  
answer.

I modified ruby/gems/1.8/gems/rails-0.14.3/lib/fcgi\_handler.rb as below.

def exit\_now\_handler(signal)  
dispatcher\_log :info, “asked to terminate immediately”  
## force to restart  
dispatcher\_log :info, “but we will restart”  
restart\_handler(signal)  
#exit  
end

For signal TERM, I force dispatch.fcgi not to exit but restart. It looks  
weird but at least works for me. User will not see 500 error anymore,  
and  
will only need to wait a while to restart dispatch.fcgi if something  
goes  
wrong.

Gary
