Skip to content

Commit eaf6151

Browse files
committed
Delete expired session files when there is no traffic
Most HTTP requests create a file in the sessions directory. Open browsers call "/misc/cleanup" every five minutes, but session files can accumulate after browsers are closed. Wake periodically to delete expired sessions according to the CHECK_SESSION_FILES_INTERVAL setting. Fixes: #1999 Fixes: #8355 Updates: #2097
1 parent e966f64 commit eaf6151

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

web/pgadmin/misc/__init__.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
from pgadmin.utils.heartbeat import log_server_heartbeat, \
2626
get_server_heartbeat, stop_server_heartbeat
2727
import config
28+
import threading
2829
import time
2930
import json
3031
import os
@@ -183,6 +184,19 @@ def register(self, app, options):
183184
from .workspaces import blueprint as module
184185
self.submodules.append(module)
185186

187+
def autovacuum_sessions():
188+
try:
189+
with app.app_context():
190+
cleanup_session_files()
191+
finally:
192+
# repeat every five minutes until exit
193+
# https://github.com/python/cpython/issues/98230
194+
t = threading.Timer(5 * 60, autovacuum_sessions)
195+
t.daemon = True
196+
t.start()
197+
198+
app.register_before_app_start(autovacuum_sessions)
199+
186200
super().register(app, options)
187201

188202

@@ -213,8 +227,6 @@ def ping():
213227
@pgCSRFProtect.exempt
214228
def cleanup():
215229
driver.ping()
216-
# Cleanup session files.
217-
cleanup_session_files()
218230
return ""
219231

220232

0 commit comments

Comments
 (0)