Code

Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#9262 closed (invalid)

Memory leak in django.utils.version.get_svn_revision

Reported by: semenov Owned by: nobody
Component: Uncategorized Version: master
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

django.utils.version.get_svn_revision suffers from a memory leak: it opens a file without closing it. I'm attaching the trivial patch.

Attachments (1)

9107.patch (628 bytes) - added by semenov 6 years ago.

Download all attachments as: .zip

Change History (5)

Changed 6 years ago by semenov

comment:1 Changed 6 years ago by Daniel Pope <dan@…>

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to invalid
  • Status changed from new to closed

Python files are automatically closed when the reference count drops to zero, which happens immediately in this case.

For example:

>>> import os
>>> f = open('foo')
>>> f.fileno()
3
>>> os.fstat(3)
(33188, 4672869, 65024L, 1, 1000, 1000, 5111, 1222865095, 1217326625, 1217326625)
>>> del f
>>> os.fstat(3) 
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OSError: [Errno 9] Bad file descriptor

comment:2 Changed 6 years ago by mrts

  • Resolution invalid deleted
  • Status changed from closed to reopened

You can't assume CPython refcounting now that Django runs officially on Jython.

Quote from http://jython.sourceforge.net/docs/differences.html:

Jython has "true" garbage collection whereas CPython uses reference counting. This means that in Jython users don't need to worry about handling circular references as these are guaranteed to be collected properly. On the other hand, users of Jython have no guarantees of when an object will be finalized -- this can cause problems for people who use open("foo", 'r').read() excessively. Both behaviors are acceptable -- and highly unlikely to change.

comment:3 Changed 6 years ago by ubernostrum

  • Resolution set to invalid
  • Status changed from reopened to closed

"no guarantees of when an object will be finalized" != "object will never be finalized". If we were opening thousands of files and never explicitly closing them, there might be a case for changes (since they might not get auto-collected soon enough), but that's not what's happening, so let it rest.

comment:4 Changed 6 years ago by semenov

I am the topic starter and I agree with closing the ticket as invalid. I was reported about the memory leak by our team profiling results and didn't check myself if it actually took place (my bad).

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.