Search Postgresql Archives

handling out of memory conditions when fetching row descriptions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi there,

using the latest git source code, I found that libpq will let the
connection stall when getRowDescriptions breaks on an out of memory
condition. I think this should better be handled differently to allow
application code to handle such situations gracefully.

For now, I changed libpq to close the connection when this happens
(please see the attached patch). This approach works fine for me so
far.

Please inform me if there are better ways to handle this.

Thanks.

Best regards,

Isidor Zeuner
diff --git a/src/interfaces/libpq/fe-protocol3.c b/src/interfaces/libpq/fe-protocol3.c
index 5c06a40..70ea020 100644
--- a/src/interfaces/libpq/fe-protocol3.c
+++ b/src/interfaces/libpq/fe-protocol3.c
@@ -270,7 +270,14 @@ pqParseInput3(PGconn *conn)
 					{
 						/* First 'T' in a query sequence */
 						if (getRowDescriptions(conn))
+						{
+							conn->asyncStatus = PGASYNC_UNEXPECTED;
+							pqsecure_close(conn);
+							closesocket(conn->sock);
+							conn->sock = -1;
+							conn->status = CONNECTION_BAD;		/* No more connection to backend */
 							return;
+						}
 
 						/*
 						 * If we're doing a Describe, we're ready to pass the
diff --git a/src/interfaces/libpq/libpq-int.h b/src/interfaces/libpq/libpq-int.h
index 04b9dd9..9130bdf 100644
--- a/src/interfaces/libpq/libpq-int.h
+++ b/src/interfaces/libpq/libpq-int.h
@@ -219,7 +219,8 @@ typedef enum
 	PGASYNC_READY,				/* result ready for PQgetResult */
 	PGASYNC_COPY_IN,			/* Copy In data transfer in progress */
 	PGASYNC_COPY_OUT,			/* Copy Out data transfer in progress */
-	PGASYNC_COPY_BOTH			/* Copy In/Out data transfer in progress */
+	PGASYNC_COPY_BOTH,			/* Copy In/Out data transfer in progress */
+	PGASYNC_UNEXPECTED			/* unexpected state */
 } PGAsyncStatusType;
 
 /* PGQueryClass tracks which query protocol we are now executing */
-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux