Django

Code

Ticket #8455 (closed: fixed)

Opened 4 months ago

Last modified 3 months ago

Lack of filesystem permissions to save uploaded file results in server hang

Reported by: carljm Assigned to: nobody
Milestone: 1.0 Component: File uploads/storage
Version: SVN Keywords:
Cc: Triage Stage: Accepted
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description

If the web server user does not have filesystem permissions to write to the "upload_to" directory of a FileField? or ImageField?, attempting to upload a file results in the server process hanging and eating 100% CPU.

Instead, there should be a 500 error or debug page with a sensible error message.

This issue seems to exist ever since file-storage-refactor. I can replicate it on both the Django development server and Apache 2.2 on Debian Linux.

I believe the problem is that django.core.file.storage.FileSystemStorage?._save() makes unwarranted assumptions about the reason for an OSError, causing an infinite loop, as outlined by rajeshdhawan in this comment on #8203.

Attachments

issue-8455.diff (0.9 kB) - added by carljm on 08/20/08 14:50:33.
patch to check OSError error number
issue-8455.errno.diff (0.9 kB) - added by carljm on 08/20/08 15:38:39.
better patch, uses os.errno.EEXISTS instead of raw error number
issue-8455.errno2.diff (1.0 kB) - added by carljm on 08/20/08 16:17:00.
os.errno is Python 2.5 only, use top-level errno instead

Change History

08/20/08 14:50:33 changed by carljm

  • attachment issue-8455.diff added.

patch to check OSError error number

08/20/08 14:54:08 changed by carljm

  • needs_better_patch changed.
  • has_patch set to 1.
  • needs_tests changed.
  • needs_docs changed.

Don't know if this is the best way to go about it, but this patch resolves the issue for me. It should also fix the problem for any other potential error condition (out of disk space, whatever) that could result in an OSError.

08/20/08 15:09:11 changed by carljm

In particular, I should note that I have no idea whether the error number checked by my patch is cross-platform or not (I've only tested on Linux). If there aren't reliable cross-platform error numbers, a good patch might need to entirely rework the logic (do an explicit test for the existence of the file and not catch OSError at all?).

08/20/08 15:38:39 changed by carljm

  • attachment issue-8455.errno.diff added.

better patch, uses os.errno.EEXISTS instead of raw error number

08/20/08 16:17:00 changed by carljm

  • attachment issue-8455.errno2.diff added.

os.errno is Python 2.5 only, use top-level errno instead

08/24/08 12:12:13 changed by jacob

  • stage changed from Unreviewed to Accepted.

08/27/08 16:44:14 changed by jacob

  • status changed from new to closed.
  • resolution set to fixed.

(In [8639]) Fixed #8455: a lack of permissions in MEDIA_ROOT no longer causes an infinite loop when saving files. Thanks, carljm.


Add/Change #8455 (Lack of filesystem permissions to save uploaded file results in server hang)




Change Properties
Action