pkluz
pkluz

Reputation: 4881

Heroku app stops responding after a couple of requests

I have an app running on a single Dyno and the free-tier PostgreSQL Add-On (sufficient for development purposes so far).

Whenever I deploy my application onto Heroku or simulate running it with foreman everything works splendidly - until it doesn't.

The requests made aren't overly complex (basic selects and inserts) and they should most certainly respond after a couple of milliseconds.

My test script invokes the routes I defined (in sequence) but sometimes just stops and times out on arbitrary requests (both on foreman and production). The app is not crashed and still running but not responding to any kind of request anymore (cURL, Browser,...)

Here's the log:

2013-12-06T11:47:59.115033+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=POST path=/users host=myapp.herokuapp.com fwd=IP dyno=web.1 connect=1ms service=30000ms status=503 bytes=0

When I restart the application and trigger said request again,...it works perfectly. Well, until it doesn't anymore ( 8-12 requests into testing ).

I also tested logging every route call, and found that the request that times out doesn't even trigger the first line of the code! Thus, I'm led to believe that the problem doesn't lie within my reponses taking to long...

What could be the reason for this? Is it some free-tier limit? I honestly hope not, because that'd mean I can singlehandedly 'crash' the server by hitting F5 a dozen times.

Upvotes: 2

Views: 1518

Answers (1)

Paul Mougel
Paul Mougel

Reputation: 17038

This is hard to debug without any code, but I'll guess that you are a victim of the Node.js socket pooling.

By default, connections in Node.js are taken from a pool of sockets. If all sockets are used, then the application waits for a socket to become available. You are probably opening databases connections that you never close (or the objects are never garbage collected due to some memory leak in your code) thus exhausting the socket pool. The solution is then to close those unused connections (or to fix the memory leaks).

Here is some documentation about the HTTP socket pool; you can also read substack's rant.

Upvotes: 3

Related Questions