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 Briney <st...@xyratex.com> on 2013/07/05 11:10:26 UTC

Python TSocket.py issue

Hi,

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)


Is this the correct way to fix the issue? Should i raise a jira ticket or
submit a patch or something?

Thanks,
Steve

-- 

*Stephen Briney*

•****

*Software Engineer*

*Xyratex*****

*office:*****

*+44 (0)2392 496542*


*www.xyratex.com* <http://www.xyratex.com/> *Connect with
Xyratex<http://blog.xyratex.com/>
*

-- 


------------------------------
For additional information including the registered office and the treatment of Xyratex confidential information please visit www.xyratex.com

------------------------------

Re: Python TSocket.py issue

Posted by Stephen Briney <st...@xyratex.com>.
Thanks,

I have opened the jira ticket
THRIFT-2085<https://issues.apache.org/jira/browse/THRIFT-2085> for
this issues.

Steve


On 5 July 2013 16:51, Carl Yeksigian <ca...@yeksigian.com> wrote:

> Opening a JIRA ticket and submitting the patch to that ticket is the best
> way to get this issue resolved. Please see
> http://thrift.apache.org/docs/HowToContribute/ for more information about
> how to contribute.
>
> Thanks,
> Carl
>
>
> On Fri, Jul 5, 2013 at 5:10 AM, Stephen Briney
> <st...@xyratex.com>wrote:
>
> > Hi,
> >
> > 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)
> >
> >
> > Is this the correct way to fix the issue? Should i raise a jira ticket or
> > submit a patch or something?
> >
> > Thanks,
> > Steve
> >
> > --
> >
> > *Stephen Briney*
> >
> > •****
> >
> > *Software Engineer*
> >
> > *Xyratex*****
> >
> > *office:*****
> >
> > *+44 (0)2392 496542*
> >
> >
> > *www.xyratex.com* <http://www.xyratex.com/> *Connect with
> > Xyratex<http://blog.xyratex.com/>
> > *
> >
> > --
> >
> >
> > ------------------------------
> > For additional information including the registered office and the
> > treatment of Xyratex confidential information please visit
> www.xyratex.com
> >
> > ------------------------------
> >
>



-- 

*Stephen Briney*

•****

*Software Engineer*

*Xyratex*****

*office:*****

*+44 (0)2392 496542*


*www.xyratex.com* <http://www.xyratex.com/> *Connect with
Xyratex<http://blog.xyratex.com/>
*

-- 


------------------------------
For additional information including the registered office and the treatment of Xyratex confidential information please visit www.xyratex.com

------------------------------

Re: Python TSocket.py issue

Posted by Carl Yeksigian <ca...@yeksigian.com>.
Opening a JIRA ticket and submitting the patch to that ticket is the best
way to get this issue resolved. Please see
http://thrift.apache.org/docs/HowToContribute/ for more information about
how to contribute.

Thanks,
Carl


On Fri, Jul 5, 2013 at 5:10 AM, Stephen Briney
<st...@xyratex.com>wrote:

> Hi,
>
> 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)
>
>
> Is this the correct way to fix the issue? Should i raise a jira ticket or
> submit a patch or something?
>
> Thanks,
> Steve
>
> --
>
> *Stephen Briney*
>
> •****
>
> *Software Engineer*
>
> *Xyratex*****
>
> *office:*****
>
> *+44 (0)2392 496542*
>
>
> *www.xyratex.com* <http://www.xyratex.com/> *Connect with
> Xyratex<http://blog.xyratex.com/>
> *
>
> --
>
>
> ------------------------------
> For additional information including the registered office and the
> treatment of Xyratex confidential information please visit www.xyratex.com
>
> ------------------------------
>