Opened 13 years ago
Closed 13 years ago
#17303 closed Bug (fixed)
Cached template loader can fail to find template in multi-threaded environment
Reported by: | Owned by: | nobody | |
---|---|---|---|
Component: | Template system | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Cached template loader resolves subloaders on demand and appends them to cached_loaders list immediately. This can lead to the usage of incomplete loader list while handling concurrent requests producing infrequent 'template not found'-exceptions.
Attachments (2)
Change History (5)
by , 13 years ago
Attachment: | patch.diff added |
---|
comment:1 by , 13 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:2 by , 13 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
I added a comment in the patch, and made the patch apply to root directory. I think this is ready for checkin, although the committer might want to check the added comment. My English is what it is...
I tried to make the loaders property a cached_property. This would work fine, but tests use the _cached_loaders variable, and I do not have the time to fix the tests. This would be a good thing to fix, but I just don't have time to do that currently. Tests are effectively dependent on the implementation details of cached template loader, but they could almost as easily use the Loader.__init__
to pass the wanted loaders.
I also checked what it would take to write a test for the concurrency issue. This would require a dummy template loader. Add it as a second loader for the cached loader. Then (using a semaphore, for example) make two threads access the loaders() property with proper timing, so that the first thread has loaded just one template loader when the second thread access the loaders() property... In short: doable, but not worth the effort IMHO. The added comment should be guard enough against regressions.
All tests passed on sqlite3.
by , 13 years ago
Attachment: | 17303.diff added |
---|
Two comments about the patch, based on just reading the diff:
So, marking as accepted. A testcase would be good, but it would also be a bit hard to write (testing race-conditions isn't too easy). I will try to review this fully tomorrow. I will see if I can find a clean way to write a testcase + of course try to apply & test the patch.