[
https://issues.apache.org/jira/browse/THRIFT-3737?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15192421#comment-15192421
]
ASF GitHub Bot commented on THRIFT-3737:
----------------------------------------
Github user cherrot commented on the pull request:
https://github.com/apache/thrift/pull/945#issuecomment-196004421
Hi, after comparing the thrift lib for Java and C++, I agree to obey the
literal meaning of `isOpen` method by Socket API convention. That is to say, a
connection is __open__ unless it was closed explicitly.
Now the problem is, since `Thrift` hides the underlying `TSocket`, unless
using some tricks, I can't acces to the `socket` object from downstream
application (say [happybase](https://github.com/wbolster/happybase) in this
case) to determine whether it should be closed. Then it becomes so easy for a
normal user to create more and more connections until reaching the system limit.
So I hope `TTransport` could add an method calls something like
`shouldClose` or `isDropped`, inside which, using something like
`select([sock], [], [], 0.0)` to determine whether this socket should be
closed. __Or__ simply expose the `TSocket` object to the outer world.
FYI, according to
http://code.activestate.com/recipes/408997-when-to-not-just-use-socketclose/#c5
:
>Now, that incoming socket, which `select` just said was readable, has no
data waiting. According to asyncore, twisted, and every other asynchronous
package I've seen, when a socket is readable(), but has no data waiting, then
the remote machine has disconnected.
> Improve TSocket isOpen() implementation to give more accurate connection
> status.
> --------------------------------------------------------------------------------
>
> Key: THRIFT-3737
> URL: https://issues.apache.org/jira/browse/THRIFT-3737
> Project: Thrift
> Issue Type: Bug
> Components: Python - Library
> Reporter: Cherrot Luo
> Labels: patch
> Original Estimate: 0h
> Remaining Estimate: 0h
>
> h2. Description
> Typically isOpen() of TSocket.py in python lib would *ALWAYS* return true,
> even if the underlying TCP connection has been closed or reset by the peer,
> unless you manually invoke its close() method.
> This is because the isOpen method takes a simple but kind of "irresponsible"
> way to judge connection status:
> {code:title=TSocket.py}
> def isOpen(self):
> return self.handle is not None
> {code}
> This may affect the downstream lib/tools' implementation to offer a
> *reliable* transport instance.
> For example, in [happybase|https://github.com/wbolster/happybase] (a
> developer-friendly Python library to interact with Apache HBase), it use
> isOpen() to judge whether it neccessary to reopen the connection in its
> [connection|https://github.com/wbolster/happybase/blob/9cbd718c10a3089f234f1eac1236b631e1f8e7cd/happybase/connection.py#L164]
> and connection pool.
> h2. Fix
> I've sent a github [Pull Request|https://github.com/apache/thrift/pull/945]
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)