We've had an ongoing problem in production where gunicorn would restart gevent workers at irregular intervals, and recently identified a case where this was happening when the worker was trying to process the upload of a large file. Uploading and thumbnailing use temp files, and in the gunicorn docs they mention that accessing files on disk-backed storage from docker images on AWS may block for excessive lengths of time.
flask-cloudy and boto3 will accept Werkzeug's FileStorage objects (which are a wrapper around io.BytesIO) instead of file paths, so change uploading and thumbnailing to use FileStorage objects instead of temp files.
I also added some logging to record when files are put in storage, and the reasons for thumbnailing failure, and increased the request timeout for fetching images for thumbnailing, to reduce thumbnailing failures when linking to something on a slow server.
We've had an ongoing problem in production where
gunicorn
would restartgevent
workers at irregular intervals, and recently identified a case where this was happening when the worker was trying to process the upload of a large file. Uploading and thumbnailing use temp files, and in thegunicorn
docs they mention that accessing files on disk-backed storage from docker images on AWS may block for excessive lengths of time.flask-cloudy
andboto3
will accept Werkzeug'sFileStorage
objects (which are a wrapper around io.BytesIO) instead of file paths, so change uploading and thumbnailing to useFileStorage
objects instead of temp files.I also added some logging to record when files are put in storage, and the reasons for thumbnailing failure, and increased the request timeout for fetching images for thumbnailing, to reduce thumbnailing failures when linking to something on a slow server.