Opened 3 years ago

Last modified 3 years ago

#28154 assigned Bug

Infinite loop in collectstatic with broken symlinks

Reported by: Matthew Somerville Owned by: ChillarAnand
Component: contrib.staticfiles Version: 1.11
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


If the static directory contains a broken symlink in place of a file that collectstatic wishes to copy*, then the code gets stuck in an infinite loop, because the fails (O_CREAT | O_EXCL will fail if a symlink exists, even if it's to a non-existent file), but then get_available_name returns the same name (as it calls self.exists, which returns False for a broken symlink).

I guess two possibilities are:

  1. don't care about broken symlinks. Change the flags setting in django/core/files/ to not include O_EXCL if os.path.islink(full_path) and not os.path.exists(full_path).
  2. do care, change os.path.exists in the exists function to use os.path.lexists instead.

I'm not sure which would be preferable to prevent this infinite loop.

*I came across this issue because collectstatic had been run both inside and outside a Vagrant box, so symlinks created inside the box did not exist when collectstatic was then run outside.

Change History (4)

comment:1 Changed 3 years ago by Tim Graham

Summary: Infinite loop in collectstaticInfinite loop in collectstatic with broken symlinks
Triage Stage: UnreviewedAccepted

comment:2 Changed 3 years ago by KwonHan Bae

I think its fixed in master branch.
should we backport to 11.x ?

comment:3 Changed 3 years ago by Tim Graham

Which commit fixed it? Most likely a fix wouldn't qualify for a backport based on our supported versions policy.

comment:4 Changed 3 years ago by ChillarAnand

Owner: changed from nobody to ChillarAnand
Status: newassigned
Note: See TracTickets for help on using tickets.
Back to Top