Skip to content

Instantly share code, notes, and snippets.

@dylanwh
Created February 19, 2018 21:17
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save dylanwh/dbb7acc97151503ef061f0895ec0d137 to your computer and use it in GitHub Desktop.

Okay, so if you run the WSGI app above with gunicorn in docker, you'll get invalid json logs.

If you run one instance of it, logs are valid. If you run it so that stdout is to a file (and not a pipe), logs are valid If you set NUMBER_OF_X to 4090 (to account for json array, quote, and newline) logs are valid.

run it like this:

docker run --rm --name guni -v (pwd):/test -w /test -d dylanwh/guni gunicorn --preload -w 25 badlogs
docker exec guni -ti /bin/bash
apt install apache2-utils
ab -c 10 -n 10000 http://localhost:8000/

inspect the output of docker logs guni 2>/dev/null

from os import environ
from sys import stdout
try:
NUMBER_OF_X = int(environ['NUMBER_OF_X'])
except KeyError:
NUMBER_OF_X = 1024 * 8
# The application interface is a callable object
def application(environ, start_response):
# Build the response body possibly
# using the supplied environ dictionary
response_body = 'Request method: %s' % environ['REQUEST_METHOD']
# HTTP response code and message
status = '200 OK'
# HTTP headers expected by the client
# They must be wrapped as a list of tupled pairs:
# [(Header name, Header value)].
response_headers = [
('Content-Type', 'text/plain'),
('Content-Length', str(len(response_body)))
]
# Send them to the server using the supplied function
start_response(status, response_headers)
# print("my fileno is {fileno}".format(fileno = stdout.fileno()))
print("[\"" + ("x" * NUMBER_OF_X) + "\"]")
stdout.flush() # broken with and without.
# Return the response body. Notice it is wrapped
# in a list although it could be any iterable.
return [bytes(response_body, 'utf-8')]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment