-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
THRIFT-3737 Improve isOpen() to give accurate tcp connection status. #945
THRIFT-3737 Improve isOpen() to give accurate tcp connection status. #945
Conversation
Hi @cherrot thanks for looking into this. Also, I don't think we want to include 3rd party code for something as simple as this. |
@nsuke Actually I didn't figure out what you mean. How can dropped connections (I mean, those in CLOSE_WAIT / CLOSE state) be OPENED connections? When I'm calling this method, what I expect is getting the correct underlying connection state, not just telling me if I have closed it by hand. Or otherwise, how could I determine when I need reconnect the underlying connection in a semantic way, instead of sending to / reading from it directly? Also, I referred to the 3rd party lib because I want to show that it's a common pattern to judge if a connection could be used, not because the LICENSE. I could reimplement this 10-line-code-block in my style if you guys prefer that :) |
The method name is is_connection_dropped and negation of it is used for isOpen. |
Marcus Dushshantha Chandradasa on dev@thrift.apache.org replies: |
Hi, after comparing the thrift lib for Java and Now the problem is, since So I hope FYI, according to http://code.activestate.com/recipes/408997-when-to-not-just-use-socketclose/#c5 :
|
To be clear, I'm not against introducing the feature you're suggesting, I've just commented on the approach.
It's same as the cases where read() returns 0 length, i.e. just plain old EOF, so you still need to check the available data. |
Thanks for reminding me that @nsuke ;) BTW do we need preserve the function name |
… be closed. like what the `peek` method does in C++ lib of Thrift.
241d58a
to
c32995d
Compare
It looks like |
As further looking into your use case (happybase), I doubt it's what you wanted. Note that almighty "this connection is fine" guarantee is very costly: even the current patch does not cover cases like invalidated file descriptor (i.e. closed socket) and half closed non-writable sockets. |
As what I described in happybase issue#112, happybase use Consider the following case: suppose Thrift server would drop a connection which was idle for 2min, and the client side communicates with Thrift server every 1 to 5min. With the current implementation the client side would encounter extremely frequent network failures.
Compared with the former case, this patch is quite efficient (no underlying network communication, no blocking). And I don't think it breaks the KISS rule. At least you don't need to put your failover code everywhere. Of course we cannot cover all the circumstances of a connection's possible state, but we can try our best to give a probably healthy connection for the moment. For other circumstances, it depends on the user's decision (to let it die or have a retry logic). After all, what this patch does is providing a convenient way to test the connection. It never forces developers to use this in their application or libs. |
isOpen call seems to be for only lazy initialization but it might not the point we should discuss in here. If happybase's pool needs something similar to urllib3's pool, it's perfectly possible without modifying Thrift: just store TSocket instance and use its |
A try-except block is surely needed when we do something relative to the physical world, but we are not discussing on that, are we? And a try-failed-retry logic is inefficient.
Yes it is possible, but far from perfect: the Furthermore, if this is not the approach you prefer, then why is there a |
System calls are much more inefficient than exceptions, at least for Python.
It's the same as TTransport for TProtocol. |
Yes you are right, using As a lower layer library, I think it would be nice to provide a convenient API telling the underlying state. Users could decide whether to use this or not. And what is the |
It seems that a |
Reminder, this needs to move forward. |
There's no real use case anymore. happybase does not use Apache Thrift any longer. |
If that is the case and the change is no longer desired, we need to close this out somehow. |
OK I agree to close this PR. |
Origin issue: https://issues.apache.org/jira/browse/THRIFT-3737
To give user a more accurate connection state by invoking TSocket.isOpen().
The code refers to urllib3's implimentation.