You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@thrift.apache.org by "Stephen David Briney (JIRA)" <ji...@apache.org> on 2013/07/08 19:47:49 UTC

[jira] [Updated] (THRIFT-2085) TTransport.TBufferedTransport.isOpen() will return true, even if the connection has failed to connect in Python

     [ https://issues.apache.org/jira/browse/THRIFT-2085?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Stephen David Briney updated THRIFT-2085:
-----------------------------------------

    Attachment: thrift-0.9.1-isOpen-issue.patch
    
> TTransport.TBufferedTransport.isOpen() will return true, even if the connection has failed to connect in Python
> ---------------------------------------------------------------------------------------------------------------
>
>                 Key: THRIFT-2085
>                 URL: https://issues.apache.org/jira/browse/THRIFT-2085
>             Project: Thrift
>          Issue Type: Bug
>          Components: Python - Library
>    Affects Versions: 0.9.1
>            Reporter: Stephen David Briney
>         Attachments: thrift-0.9.1-isOpen-issue.patch
>
>
> We have been using the python thrift lib and I noticed some strange behaviour: -
> If i call: -
> transport = TTransport.TBufferedTransport(self.socket)
> transport.open()
> transport.isOpen()
> The isOpen() will return true, even if the connection failed.
> I have traced the problem down to class TSocket. The isOpen method works like this:-
> def isOpen(self):
>     return self.handle is not None
> But if open fails it will not set self.handle back to None: -
> def open(self):
>     try:
>       res0 = self._resolveAddr()
>       for res in res0:
>         self.handle = socket.socket(res[0], res[1])
>         self.handle.settimeout(self._timeout)
>         try:
>           self.handle.connect(res[4])
>         except socket.error, e:
>           if res is not res0[-1]:
>             continue
>           else:
>             raise e
>         break
>     except socket.error, e:
>       if self._unix_socket:
>         message = 'Could not connect to socket %s' % self._unix_socket
>       else:
>         message = 'Could not connect to %s:%s' % (self.host, self.port)
>       raise TTransportException(type=TTransportException.NOT_OPEN,
>                                 message=message)
> Setting self.handle to None when the connection fails fixes my issue: -
> def open(self):
>     try:
>       res0 = self._resolveAddr()
>       for res in res0:
>         self.handle = socket.socket(res[0], res[1])
>         self.handle.settimeout(self._timeout)
>         try:
>           self.handle.connect(res[4])
>         except socket.error, e:
>           if res is not res0[-1]:
>             continue
>           else:
>             self.handle = None
>             raise e
>         break
>     except socket.error, e:
>       if self._unix_socket:
>         message = 'Could not connect to socket %s' % self._unix_socket
>       else:
>         message = 'Could not connect to %s:%s' % (self.host, self.port)
>       raise TTransportException(type=TTransportException.NOT_OPEN,
>                                 message=message)
> Please see attached patch.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira