-
Notifications
You must be signed in to change notification settings - Fork 163
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
Regression: Connection fails re-opening connections in 1.0.0? #133
Comments
could be different behaviour in other python lib: thriftpy vs thrift (different dependencies in those versions). also, stack trace gives more info perhaps? |
So I can actually simplify the error, happybase just cannot cleanly close and re-open a connection:
Fails on the second call. Stack trace is the same for both
|
For context I'll add my justifying use case. I get frequent timeouts in the form:
So I use a subclass of
I can't simply let |
since https://github.com/wbolster/happybase/blob/master/happybase/connection.py#L169-L178 |
I'm not sure I understand the underlying bug/difference between thriftpy and thrift, but more importantly, based on my understanding of the code, I think this should be addressable by Expected behavior of
Unless you need persistent transport/client/etc objects for some reason? I know that |
cause identified in other ticket, relying on |
thriftpy is bumped to 0.3.9, do you want to up requirements and release 1.0.1? I'll consider a pull request for the other issues |
does happybase need changes? or is just bumping the thriftpy dep enough? |
i think the dep is enough here, if i have time i'll try a pull request to make more robust but the acute issue is resolved by thriftpy |
I still get the |
Here is what I currently have deployed, although I have not recently verified whether the extra work is still necessary class AutoRetryPool(ConnectionPool):
"""Connection pool which does its best to ensure open connections
May impose some overhead (ie not good for low-latency stuff) but should
increase reliability of getting a working, open connection when needed
"""
def __init__(self, size, retries=5, **kwargs):
self.retries = retries
super(AutoRetryPool, self).__init__(size, **kwargs)
@contextmanager
def connection(self, timeout=None):
attempts = 0
opened = False
while True:
try:
with super(AutoRetryPool, self).connection(timeout=timeout) as conn:
# Make an actual call to ensure
_ = conn.tables()
opened = True
yield conn
return
except (TException, socket.error):
# These trigger refreshed connections in parent
if opened:
# aka the failure was inside the yield, can't fix
raise
attempts += 1
# print 'Replacing connection, attempt', attempts
if attempts >= self.retries:
raise
def _return_connection(self, connection):
# Don't leave idling connections around - too easy to timeout before use
connection.close()
return super(AutoRetryPool, self)._return_connection(connection) |
Thanks! I will test this and get back to you! |
I believe this may be caused by |
@gorlins Thanks for the AutoRetryPool. I tried with the
Also, sometimes I see the following error happening during
|
@pranny it Iooks like you didn't copy the error on the first issue, so I can't really comment... the latter issue looks like you have not configured the client correctly, so you need to check your server's transport and protocol and configure the client as such https://happybase.readthedocs.io/en/latest/api.html#happybase.Connection. Also, just to beg the question, why are you scanning/using HBase at all if your table only has 2 rows? |
@gorlins @wbolster I scanned this page for info, but it's quite a long time since the last reply. Is there any resolution to this problem? Is there any plan to address this problem? I am getting Thanks for the |
According to https://github.com/Thriftpy/thriftpy, |
I think it has already fixed in thriftpy2, see Thriftpy/thriftpy2@ce522cc, thanks. |
happybase 1.2.0 uses thriftpy2: https://happybase.readthedocs.io/en/latest/news.html#happybase-1-2-0 |
Hi I am using Happybase 1.2.0 and thriftpy2 0.4.4 and still facing this issue. Steps to reproduce:-
Result:- I get the following exception. thriftpy2.transport.TTransportException: TTransportException(type=4, message='TSocket read 0 bytes') |
I think it is by design in thriftpy2, EOF would be returned if this connection closed. |
So as a conclusion the connection pooling in happybase does not work? |
I think HappyBase should catch this exception if it builds a connection pool in itself. |
The http://www.programmersought.com/article/41421562488/;jsessionid=660BCDAD2F7713EAE1A111B2255FD2FA HBASE is hanging up on us while we have an active connection, and there is nothing gorlins code or happybase can really do to repair that. That is this bit: if opened:
# aka the failure was inside the yield, can't fix
raise So, if you're doing something like: with pool.connection() as conn:
t = conn.table("foo")
t.put("1", {})
# do something expensive for 60s
sleep(60)
# try to write some more data, BOOM BrokenPipeError!
t.put("2", {}) You're going to get an explosion when that second The solution unfortunately is to open new connections for each set of operations after the expensive thing. with pool.connection() as conn:
t = conn.table("foo")
t.put("1", {})
# close that one.
# do something expensive and time consuming, this time without an active conn.
sleep(60)
# open up another one
with pool.connection() as conn:
t = conn.table("foo")
t.put("2", {}) @ankitgaur So yes, connection pooling in happybase does not work. Also, even if it did work HBASE is going to hang up on you anyway. |
Hi @nackjicholson, it can be a walk-around. However, catching the losing connection exception in HappyBase can totally resolve this issue. |
I believe that ConnectionPool doesn't play nice with 1.0, and can yield broken connections even in the best case scenarios. Here's my reproducing code:
Works for 0.9:
But not 1.0.0:
Given that
ConnectionPool.connection()
callsopen()
before yielding in both versions, I can't immediately see what causes this. I am using CDH 5.7 w/ hbase 1.2.0-cdh5.7.1.The text was updated successfully, but these errors were encountered: