# Thin Webserver keeps going down

**URL:** <https://www.ruby-forum.com/t/thin-webserver-keeps-going-down/158879>\
**Category:** Deployment\
**Created:** [January 29, 2009, 1:09am UTC](https://www.ruby-forum.com/t/thin-webserver-keeps-going-down/158879 "2009-01-29T01:09:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![butterchops](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/439d5e/32.png) [@butterchops](https://www.ruby-forum.com/u/butterchops)\
**Post date:** [January 29, 2009, 1:09am UTC](https://www.ruby-forum.com/t/thin-webserver-keeps-going-down/158879/1 "2009-01-29T01:09:56Z")

</div>

Hey all,

Have just released my first RoR application into a production setting on  
a VPS and am having some stability troubles with Thin. After roughly 1  
hour of running the webserver it will fail and I will have to login to  
the VPS and restart it. Not exactly sure what the deal is but the most  
recent entry in my thin.log presents the following:

> > Writing PID to tmp/pid/thin.12001.pid  
> > Changing process privilege to root:root  
> > Using rails adapter  
> > Thin web server (v1.0.0 codename That’s What She Said)  
> > Maximum connections set to 1024  
> > Listening on 0.0.0.0:12001, CTRL+C to stop  
> > 1714793619361936120889361936112791112791472676\>\> Stopping …  
> > [FATAL] failed to allocate memory

I’ve checked on memory usage when Thin is operating, according to top it  
is on a round 58m res and 67 virt (22.7% mem). Is this high? Could a  
runaway memory leak be causing the Thin process to eventually abort? If  
this is likely to be my problem is there any way I can debug/resolve  
this?

FWIW, I have setup thin according to the guide over at  
[http://railsforum.com/viewtopic.php?id=17284](http://railsforum.com/viewtopic.php?id=17284) - thin can be started,  
restarted and stopped through /etc/init.d/thin. The two things I  
changed was I only had a single server running (didn’t see the point in  
running 5 instances) and I am running the server as root.

Ideally I’d like to get to the bottom of why Thin is aborting and try  
and resolve that, but if I can’t I would like to know if there’s any way  
to get my server to automatically start thin when it fails?

Any assistance would be appreciated. Thanks in advance.

---

<div class="post-metadata">

**Author:** ![butterchops](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/439d5e/32.png) [@butterchops](https://www.ruby-forum.com/u/butterchops)\
**Post date:** [February 5, 2009, 7:26pm UTC](https://www.ruby-forum.com/t/thin-webserver-keeps-going-down/158879/2 "2009-02-05T19:26:25Z")

</div>

Re Miara wrote:

> Ideally I’d like to get to the bottom of why Thin is aborting and try  
> and resolve that, but if I can’t I would like to know if there’s any way  
> to get my server to automatically start thin when it fails?

Hm, could be also your rails application not freeing the memory. Have  
you turned your Garbage Collector off maybe? Have you tried using a  
Webrick instead to test this behaviour?

For the automatically restart thing, I personally use god:  
[http://rubyforge.org/projects/god/](http://rubyforge.org/projects/god/)

Configure it like this:  
[http://glauche.de/2008/02/15/a-thin-god/](http://glauche.de/2008/02/15/a-thin-god/)

This will periodically check your thin processes for excessive memory or  
cpu usage and will check if they are alive. On any problem god will  
automatically restart them.

> and I am running the server as root  
> Don’t do that. In case of any exploit through the framework or your  
> application an attacker could get full root access to your machine.
