Skip to content

Commit 89dab7a

Browse files
authored
Close existing connection before job execution in worker (#1959)
* Close existing DB connection before job execution in worker The tech stack of django-rq seems to have issues with TLS connections getting corrupted when using the Worker class, which uses fork. This is relevant when an external database is used. This problem can be avoided by closing the existing connection prior to the call to `execute_job`. For reference see: #1523 and rq/django-rq#650 Signed-off-by: Robert Guetzkow <robert.guetzkow@betasystems.com> * Move ScanCodeIOWorker modification for TLS connection issues to dedicated class The current default is kept and the new worker class with the workaround can be enabled through the `--worker-class` option of rqworker, if needed Signed-off-by: Robert Guetzkow <robert.guetzkow@betasystems.com> --------- Signed-off-by: Robert Guetzkow <robert.guetzkow@betasystems.com>
1 parent 77cd6e0 commit 89dab7a

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

scancodeio/worker.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,21 @@ def run_maintenance_tasks(self):
5454
scanpipe_app.sync_runs_and_jobs()
5555

5656

57+
class ScanCodeIOTlsWorker(ScanCodeIOWorker):
58+
"""
59+
Modified version of RQ Worker including ScanCode.io customizations for
60+
maintainance task and TLS.
61+
"""
62+
63+
def execute_job(self, job, queue):
64+
"""
65+
Terminate existing connection to avoid issues with TLS.
66+
https://github.com/aboutcode-org/scancode.io/issues/1523
67+
"""
68+
connection.close()
69+
super().execute_job(job, queue)
70+
71+
5772
class ScanCodeIOQueue(Queue):
5873
"""Modified version of RQ Queue including ScanCode.io customizations."""
5974

0 commit comments

Comments
 (0)