#28500: "EOFError: Ran out of input" from Django file cache when file is empty
-----------------------------------------------+------------------------
Reporter: Justin Crown | Owner: nobody
Type: Bug | Status: new
Component: Core (Cache system) | Version: 1.11
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-----------------------------------------------+------------------------
When using Django file cache, if a cache file ends up empty for some
reason (yes, this actually happened in the wild), an `EOFError` is thrown.
Steps to reproduce:
Cache must be set to
`django.core.cache.backends.filebased.FileBasedCache`.
{{{
>>> from django.core.cache import cache
>>> cache.set('testing' 'test')
}}}
In a shell
{{{
> cache_dir/file_that_got_created.djcache
}}}
Back in the REPL
{{{
>>> cache.get('testing')
Traceback (most recent call last):
File "/usr/local/lib/python3.6/code.py", line 91, in runcode
exec(code, self.locals)
File "<console>", line 1, in <module>
File "/usr/local/lib/python3.6/site-
packages/django/core/cache/backends/filebased.py", line 40, in get
if not self._is_expired(f):
File "/usr/local/lib/python3.6/site-
packages/django/core/cache/backends/filebased.py", line 137, in
_is_expired
exp = pickle.load(f)
EOFError: Ran out of input
}}}
As to how these files would end up empty to begin with, I would hazard to
guess that it is caused by a rare race condition in the file moving
process:
https://github.com/django/django/blob/master/django/core/files/move.py#L59
Whereby if this process is interrupted by a system shutdown, the file is
created in the appropriate location but is empty.
Desired behavior would be that in this situation, an exception would not
be thrown. Rather, `None` (or default) would be returned.
I am planning on working on a patch towards this, but wanted to log the
ticket first.
--
Ticket URL: <https://code.djangoproject.com/ticket/28500>
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 post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/049.78eb937549fcd1d187d892d09c23e766%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.