Skip to content

Add pool_timeout and fix buggy connection pool locking #102

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

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions mysql-connector-python/lib/mysql/connector/pooling.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,7 @@ def __init__(
pool_size: int = 5,
pool_name: Optional[str] = None,
pool_reset_session: bool = True,
pool_timeout: int = 5,
**kwargs: Any,
) -> None:
"""Constructor.
Expand All @@ -456,6 +457,10 @@ def __init__(
pool_size: The pool size. If this argument is not given, the default is 5.
pool_reset_session: Whether to reset session variables when the connection
is returned to the pool.
pool_timeout: The maximum number of seconds to wait when attempting to retrieve
a connection from the pool. If no connection becomes available
before the timeout expires, a `PoolError` is raised indicating
that the pool is exhausted.
**kwargs: Optional additional connection arguments, as described in [1].

Examples:
Expand All @@ -475,6 +480,7 @@ def __init__(
self._pool_size: Optional[int] = None
self._pool_name: Optional[str] = None
self._reset_session = pool_reset_session
self._pool_timeout: int = pool_timeout
self._set_pool_size(pool_size)
self._set_pool_name(pool_name or generate_pool_name(**kwargs))
self._cnx_config: Dict[str, Any] = {}
Expand Down Expand Up @@ -649,12 +655,12 @@ def get_connection(self) -> PooledMySQLConnection:
Raises:
PoolError: On errors.
"""
try:
cnx = self._cnx_queue.get(block=True, timeout=self._pool_timeout)
except queue.Empty as err:
raise PoolError("Failed getting connection; pool exhausted") from err

with CONNECTION_POOL_LOCK:
try:
cnx = self._cnx_queue.get(block=False)
except queue.Empty as err:
raise PoolError("Failed getting connection; pool exhausted") from err

if (
not cnx.is_connected()
or self._config_version != cnx.pool_config_version
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy