From 2b208b8268c6418ef388c6948502ef161d9f66d2 Mon Sep 17 00:00:00 2001 From: Erik Cederstrand Date: Fri, 28 Oct 2016 14:20:34 +0200 Subject: [PATCH] Explicitly close the opened connection If a connection pool is created in a multiprocess environment, e.g. in settings.py of a Django app hosted by uWSGI with multiple workers, spawning processes will inherit the open fd and may close a connection that the parent process is still using. Unfortunately, I was unable to create a simple test case to trigger this. --- happybase/pool.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/happybase/pool.py b/happybase/pool.py index 2d6fee2..06cab82 100644 --- a/happybase/pool.py +++ b/happybase/pool.py @@ -75,7 +75,9 @@ def __init__(self, size, **kwargs): # The first connection is made immediately so that trivial # mistakes like unresolvable host names are raised immediately. # Subsequent connections are connected lazily. - with self.connection(): + with self.connection() as conn: + # Close the connection explicitly. Otherwise spawning processes may inherit the open fd. + conn.close() pass def _acquire_connection(self, timeout=None):