I have a simple flask application running on heroku:
from flask import Flask
app = Flask(__name__)
@app.route('/test', methods=['POST'])
def test():
return 'OK'
Incredibly it succeeds or fails, depending on the size of the json I send. Here's the test code:
import json, random, string, requests
def rand_string(size):
return ''.join([random.choice(string.letters) for i in xrange(size)])
for size in (4000, 10000):
r = requests.post('http://my-app.herokuapp.com/test',
data=json.dumps(rand_string(size)),
headers={'content-type': 'application/json'})
print r.status_code
On the first call it returns status 200, on the second http status 503 with a H13 heroku error code.
2014-09-18T08:23:46.594543+00:00 heroku[router]: at=error code=H13 desc="Connection closed without response" method=POST path="/test" host=my-app.herokuapp.com request_id=91b1cd91-5a4f-445e-ad52-3c64733154b3 fwd="12.34.56.78" dyno=web.1 connect=5ms service=13ms status=503 bytes=0
HTTP response 503 means:
server is currently unable to handle the request due to a temporary overloading or maintenance of the server
This couldn't be the case, as the server is up and running and has no load except for my manual tests.
Heroku's H13 code documentation says:
This error is thrown when a process in your web dyno accepts a connection, but then closes the socket without writing anything to it.
However all the code does is return 'OK'
so it ain't the code.
Does heroku limit the size of requests? Does gunicorn?
How can I find out and how do I configure it otherwise?