Skip to content
Advertisement

Falcon server with SSL stops working after some hours/days

I set up a very basic Python API server with falcon along the example given in the documentation. And it seems to work just fine.

Now I extended the code to support HTTPS requests using SSL certificates

import ssl

httpd = simple_server.make_server('', 8000, app)
httpd.socket = ssl.wrap_socket(
        httpd.socket, server_side=True,
        certfile='cert.pem',
        keyfile='key.pem')
httpd.serve_forever()

And again, it seems to work and HTTPS requests are served perfectly fine…in the beginning.

However, after a while — maybe a few hours or 1-2 days (no heavy load during testing) — the server hangs and no longer accepts any requests. Not even with Telnet I can make any kind of connection. The server script doesn’t show any errors, and Ubuntu tells me that some process is still listening on this port.

Where do I go from here? I don’t even know how to troubleshoot. With the basic HTTP server, I haven’t experienced any issues so far

Advertisement

Answer

As discussed in the above comments, wsgiref‘s simple_server isn’t really suitable for production.

Assuming your application is contained in app.py, and you installed gunicorn into your current Python (virtual) environment, you can run your application with TLS as:

gunicorn -b 0.0.0.0:443 --workers 8 --certfile /path/to/your/cert/cert.pem --key=/pat/to/your/cert/privkey.pem --access-logfile - app:app

(You should of course tune the number of workers, threads, etc according to your application’s needs.)

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement