﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
31637	Registering database connections for cleanup on fork	Aarni Koskela	Josh Thomas	"When using `multiprocessing.Pool()` or other process-forking APIs, one might bump into 

{{{
django.db.utils.OperationalError: SSL error: decryption failed or bad record mac
}}}

or similar inconsistency errors in the child processes, since the socket is passed down into the forked process.

The quick fix is to 

{{{
from django import db
db.connections.close_all()
}}}

before forking.

Python 3.7 introduced the `os.register_at_fork` function: [https://docs.python.org/3.8/library/os.html#os.register_at_fork]

It could be a good idea for Django to use this function to register database connections to be discarded (not cleanly closed, just dropped, as far as a forked process is concerned!) in forked child processes? That way the parent process could use established connection state as before.
"	New feature	assigned	Database layer (models, ORM)	3.0	Normal			Simon Charette	Accepted	1	0	0	1	0	0
