Author marcin.bachry
Recipients, csapuntz, dugan, janssen, marcin.bachry, pitrou
Date 2009-05-11.23:45:07
SpamBayes Score 1.68051e-07
Marked as misclassified No
Message-id <>
I think there are two bugs spotted here. The first is the mentioned
missing "close" param to _fileobject in makefile() method.

The second one was noticed by Jonathan. He doesn't use makefile() at
all, yet his socket isn't closed either. Here's what I think is going on:

The raw filesystem socket seems to be closed only upon garbage
collection, when reference count of socket._realsocket drops to zero
(ie. it's not closed explicitly anywhere). _realsocket is wrapped by
socket._socketobject and all its close() method does is dropping
reference to _realsocket object it wraps.

The bug goes like this:
1. plain = socket.create_connection(...)
   it creates and wraps a native _realsocket (plain._sock) with
reference count = 1; "plain" is an instance of _socketobject
2. secure = ssl.wrap_socket(plain)
   because SSLSocket inherits from _socketobject, it also wraps
_realsocket plain._sock and the reference count is 2 now
3. secure.close()
   it calls in turn it's parent method close() which simply drops raw
_realsocket reference count to 1
4. native socket is still referenced by plain._sock and filesystem
descriptor isn't closed unless plain.close() is called too and refcount
drops to zero

I attach the simplest possible test to prove the bug.
Date User Action Args
2009-05-11 23:45:10marcin.bachrysetrecipients: + marcin.bachry, janssen, pitrou, dugan, csapuntz,
2009-05-11 23:45:10marcin.bachrysetmessageid: <>
2009-05-11 23:45:09marcin.bachrylinkissue5238 messages
2009-05-11 23:45:08marcin.bachrycreate