From 501aa61e19bccab9587dc340ec6432c09dff8a6a Mon Sep 17 00:00:00 2001 From: dgtlmoon Date: Sun, 15 Feb 2026 08:19:29 +0100 Subject: [PATCH] Disable content compression of HTML/etc by default due to memory leak between flask_socketio and flask and flask_compress. --- changedetectionio/flask_app.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/changedetectionio/flask_app.py b/changedetectionio/flask_app.py index f6375138d..9f0cebb85 100644 --- a/changedetectionio/flask_app.py +++ b/changedetectionio/flask_app.py @@ -70,13 +70,17 @@ socketio_server = None # Enable CORS, especially useful for the Chrome extension to operate from anywhere CORS(app) -# Super handy for compressing large BrowserSteps responses and others -# Flask-Compress handles HTTP compression, Socket.IO compression disabled to prevent memory leak +# Flask-Compress handles HTTP compression, Socket.IO compression disabled to prevent memory leak. +# There's also a bug between flask compress and socketio that causes some kind of slow memory leak +# It's better to use compression on your reverse proxy (nginx etc) instead. +if strtobool(os.getenv("FLASK_ENABLE_COMPRESSION")): + app.config['COMPRESS_MIN_SIZE'] = 2096 + app.config['COMPRESS_MIMETYPES'] = ['text/html', 'text/css', 'text/javascript', 'application/json', 'application/javascript', 'image/svg+xml'] + # Use gzip only - smaller memory footprint than zstd/brotli (4-8KB vs 200-500KB contexts) + app.config['COMPRESS_ALGORITHM'] = ['gzip'] + compress = FlaskCompress() -app.config['COMPRESS_MIN_SIZE'] = 2096 -app.config['COMPRESS_MIMETYPES'] = ['text/html', 'text/css', 'text/javascript', 'application/json', 'application/javascript', 'image/svg+xml'] -# Use gzip only - smaller memory footprint than zstd/brotli (4-8KB vs 200-500KB contexts) -app.config['COMPRESS_ALGORITHM'] = ['gzip'] + compress.init_app(app) app.config['TEMPLATES_AUTO_RELOAD'] = False