Skip to content
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

fix pool bug #113

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 0 additions & 13 deletions eventlet/db_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,19 +175,6 @@ def _safe_close(self, conn, quiet=False):
def get(self):
conn = super(BaseConnectionPool, self).get()

# None is a flag value that means that put got called with
# something it couldn't use
if conn is None:
try:
conn = self.create()
except Exception:
# unconditionally increase the free pool because
# even if there are waiters, doing a full put
# would incur a greenlib switch and thus lose the
# exception stack
self.current_size -= 1
raise

# if the call to get() draws from the free pool, it will come
# back as a tuple
if isinstance(conn, tuple):
Expand Down
33 changes: 22 additions & 11 deletions eventlet/pools.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,22 +75,33 @@ def __init__(self, min_size=0, max_size=4, order_as_stack=False, create=None):
self.current_size += 1
self.free_items.append(self.create())

def _safe_create(self):
try:
return self.create()
except Exception as e:
if not self.waiting():
self.current_size -= 1
raise
else:
# put will cause a greenlet switch which destroys the
# exception info, so we have to raise the exception explicitly
self.put(None)
raise e

def get(self):
"""Return an item from the pool, when one is available. This may
cause the calling greenthread to block.
"""
if self.free_items:
return self.free_items.popleft()
self.current_size += 1
if self.current_size <= self.max_size:
try:
created = self.create()
except:
self.current_size -= 1
raise
return created
self.current_size -= 1 # did not create
return self.channel.get()
item = self.free_items.popleft()
elif self.current_size < self.max_size:
self.current_size += 1
item = self._safe_create()
else:
item = self.channel.get()
if item is None:
item = self._safe_create()
return item

@contextmanager
def item(self):
Expand Down