#31637: Registering database connections for cleanup on fork
-------------------------------------+-------------------------------------
Reporter: Aarni | Owner: nobody
Koskela |
Type: New | Status: new
feature |
Component: Database | Version: 3.0
layer (models, ORM) |
Severity: Normal | Keywords:
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
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.
--
Ticket URL: <https://code.djangoproject.com/ticket/31637>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/046.1fd03320afaa3af31e3a59b512513a09%40djangoproject.com.