Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 695595a

Browse filesBrowse files
jhm180Ace Nassri
authored andcommitted
Fix "conn pool exhausted" issue. (GoogleCloudPlatform#2040)
Updated code to return connection to pool before returning a value from the "With" block. When I tried running demo code in a gcloud function without using .putconn() to return the connection to the pool, 3 out of every 4 function invocations failed and returned error "connection pool exhausted" while fourth invocation worked successfully. Note that creating a cursor object using a With statement doesn't automatically return a connection to the pool after the With statement executes - psycopg/psycopg2#367
1 parent c2d8a9e commit 695595a
Copy full SHA for 695595a

File tree

Expand file treeCollapse file tree

1 file changed

+3
-1
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+3
-1
lines changed

‎functions/sql/postgres_sample.py

Copy file name to clipboardExpand all lines: functions/sql/postgres_sample.py
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,10 @@ def postgres_demo(request):
6161

6262
# Remember to close SQL resources declared while running this function.
6363
# Keep any declared in global scope (e.g. pg_pool) for later reuse.
64-
with pg_pool.getconn().cursor() as cursor:
64+
with pg_pool.getconn() as conn:
65+
cursor = conn.cursor()
6566
cursor.execute('SELECT NOW() as now')
6667
results = cursor.fetchone()
68+
pg_pool.putconn(conn)
6769
return str(results[0])
6870
# [END functions_sql_postgres]

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.