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 */
