[MERGE] Transport.readv() closes the file handle
John Arbash Meinel
john at arbash-meinel.com
Sat Oct 25 01:37:30 BST 2008
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
The default implementation of Transport.readv(), and the one used by
LocalTransport, is to do a regular ".get()" and then call .seek() and
.read() on the resulting file object.
This works fine, but it turns out that it leaves the file handle open on
Windows. Probably the biggest reason is that most of the callers of
.readv() actually iterate in lock-step with some other iterator (which
names the return values).
Because of this, the readv() generator never runs to completion, and
thus the file handle doesn't get closed and garbage collected right away.
The attached patch changes it so that we know when we are done reading
data from the file, and close it.
I ran into this because in my "pack retry" code the test was failing on
Windows because the .pack file handle was still open, even though I know
we were done reading that file.
_seek_and_read() is the default readv() handler. It should actually be
safe for all transports we have implemented, because the .close() will
be on objects where it is safe. The only danger would be something like
HTTP where the returned object could have been the socket we were
reading from, but a long time ago we switched to using a cStringIO
wrapper because gzip needed a .tell()/.seek() though our tuned_gzip does
not. And even so HTTP has a custom readv() implementation anyway.
So that only leaves the WebDav plugin, but I'm guessing it inherits from
the HTTP code, and not the raw Transport. I don't know of any other
active Transport implementations (at one point I had an RsyncTransport,
IIRC).
John
=:->
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iEYEARECAAYFAkkCakoACgkQJdeBCYSNAAOc9ACgi7RpXB/VL6jjDUSiscrxiEn0
yNoAoMQqLNxuizk0XEsIRTZg/mpigNEy
=UbCP
-----END PGP SIGNATURE-----
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: readv_close.patch
Url: https://lists.ubuntu.com/archives/bazaar/attachments/20081024/26a6fdfa/attachment.diff
More information about the bazaar
mailing list