Code

Opened 6 years ago

Closed 2 years ago

#6499 closed Cleanup/optimization (invalid)

Close open file descriptors on compression

Reported by: Bastian Kleineidam <calvin@…> Owned by: nobody
Component: Core (Other) Version: master
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Close another file descriptor leak.

Attachments (2)

0046-Close-open-file-descriptors.patch (1.1 KB) - added by Bastian Kleineidam <calvin@…> 6 years ago.
6499-2.diff (595 bytes) - added by claudep 2 years ago.
Updated to current trunk

Download all attachments as: .zip

Change History (9)

Changed 6 years ago by Bastian Kleineidam <calvin@…>

comment:1 Changed 6 years ago by mtredinnick

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

Firstly, unconditionally importing cStringIO isn't a good idea. It won't work with Jython.

Secondly, the file descriptor should be closed as soon as the zbuf variable goes out of scope, due to its reference count decreasing to zero. What is the situation where the file descriptor is leaking here?

comment:2 Changed 6 years ago by Bastian Kleineidam <calvin@…>

The cStringIO import was already there, so this might be good to put in a separate ticket, together with other Jython fixes probably. Thanks for the note though.

Every open file object will eventually be closed when the variable goes out of scope and the garbage collector frees it. The problem is that this is not guaranteed. The variable might be part of reference cycles, in which case the garbage collector will never free it, or the program terminates before running the garbage collection. Both cases might occur very seldom (if at all), but better be safe than sorry, since open file desriptors are especially annoying on Windows systems or network shares.

In python 2.5 you even can even use the new "with" statement to do this in a nicer way, but the compatible way is a try-finally wrapper.

comment:3 Changed 6 years ago by jacob

  • Patch needs improvement set
  • Triage Stage changed from Unreviewed to Accepted

comment:4 Changed 3 years ago by julien

  • Needs tests set
  • Severity set to Normal
  • Type set to Cleanup/optimization

Changed 2 years ago by claudep

Updated to current trunk

comment:5 Changed 2 years ago by claudep

  • Component changed from Uncategorized to Core (Other)
  • Easy pickings unset
  • Needs tests unset
  • Patch needs improvement unset
  • UI/UX unset

comment:6 Changed 2 years ago by aaugustin

I may be missing something, but we're writing to a StringIO, so there isn't a fd involved at all, let alone leaked.

comment:7 Changed 2 years ago by aaugustin

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

Closing the GzipFile is useful because it flushes its buffers. Closing the StringIO isn't necessary; it will be garbage collected eventually.

I fail to see the point of the patch: there's no fd involved in this code, and even if zbuf were a fd, the patch wouldn't close it (see http://hg.python.org/cpython/file/91cbac92a665/Lib/gzip.py#l359).

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.