View Issue Details

IDProjectCategoryView StatusLast Update
0000328Pgpool-IIBugpublic2017-08-14 13:39
Reportera.dushechkinAssigned Tot-ishii 
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionreopened 
PlatformLinuxOSUbuntuOS Version14.04
Product Version3.6.5 
Target Version3.6.6Fixed in Version 
Summary0000328: Malformed packet in response to simple query containing only '-- comment'
DescriptionPostgreSQL 9.6.3, pg_dump/pg_restore 9.6.3, 9.6.4.

If one takes DB backup with command:

  pg_dump -h $dbHost -p $dbPort -U $dbUser -d $dbName -F c -b -f $destination/$dumpname

and then restores it via pgpool with command:

  pg_restore -n public -x -U $dbUser -p $dbPort -h $dbHost --no-owner --role=$dbUser -d $dbName $destination/$dumpname

restore process outputs multiple warnings and overall return code 1, which breaks automated processes. Warnings are like:

  pg_restore: [archiver (db)] could not execute query: message contents do not agree with length in message type "C"
      Command was: -- Dumped by pg_dump version 9.6.3

There is no such issue when restoring dump directly to PostgreSQL.

On the wire if connected to PostgreSQL directly:
--> Simple query (0x51)
<-- Empty query (0x49) length 4
<-- Ready for query (0x5a), length 5, status Idle (0x49)

if connected via pgpool2:
--> Simple query (0x51)
<-- Command completion (0x43) length 4
<-- Ready for query (0x5a) of length 5, status Idle (0x49)

Also reproduced on 3.6.4, not reproduced with extended query mode (JDBC) or with psql (I believe psql just ignores comments).
Steps To ReproduceSend simple query containing only comment, like "-- comment".
TagsNo tags attached.

Activities

t-ishii

2017-08-11 19:40

developer   ~0001641

Good catch. Since psql ignores a comment only query, I did not notice it. Can you please try attached patch?

empty-query.diff (2,048 bytes)
diff --git a/src/protocol/CommandComplete.c b/src/protocol/CommandComplete.c
index 31ccece..f8ed0bb 100644
--- a/src/protocol/CommandComplete.c
+++ b/src/protocol/CommandComplete.c
@@ -40,7 +40,7 @@
 #include "utils/pool_stream.h"
 
 static int extract_ntuples(char *message);
-static POOL_STATUS handle_mismatch_tuples(POOL_CONNECTION *frontend, POOL_CONNECTION_POOL *backend, char *packet, int packetlen);
+static POOL_STATUS handle_mismatch_tuples(POOL_CONNECTION *frontend, POOL_CONNECTION_POOL *backend, char *packet, int packetlen, bool command_complete);
 static int foward_command_complete(POOL_CONNECTION *frontend, char *packet, int packetlen);
 static int foward_empty_query(POOL_CONNECTION *frontend, char *packet, int packetlen);
 static int foward_packet_to_frontend(POOL_CONNECTION *frontend, char kind, char *packet, int packetlen);
@@ -144,7 +144,7 @@ POOL_STATUS CommandComplete(POOL_CONNECTION *frontend, POOL_CONNECTION_POOL *bac
 	}
 	else
 	{
-		if (handle_mismatch_tuples(frontend, backend, p1, len1) != POOL_CONTINUE)
+		if (handle_mismatch_tuples(frontend, backend, p1, len1, command_complete) != POOL_CONTINUE)
 			return POOL_END;
 	}
 
@@ -300,7 +300,7 @@ static int extract_ntuples(char *message)
 /*
  * Handle mismatch tuples
  */
-static POOL_STATUS handle_mismatch_tuples(POOL_CONNECTION *frontend, POOL_CONNECTION_POOL *backend, char *packet, int packetlen)
+static POOL_STATUS handle_mismatch_tuples(POOL_CONNECTION *frontend, POOL_CONNECTION_POOL *backend, char *packet, int packetlen, bool command_complete)
 {
 	POOL_SESSION_CONTEXT *session_context;
 
@@ -394,8 +394,16 @@ static POOL_STATUS handle_mismatch_tuples(POOL_CONNECTION *frontend, POOL_CONNEC
 	}
 	else
 	{
-		if (foward_command_complete(frontend, packet, packetlen) < 0)
-			return POOL_END;
+		if (command_complete)
+		{
+			if (foward_command_complete(frontend, packet, packetlen) < 0)
+				return POOL_END;
+		}
+		else
+		{
+			if (foward_empty_query(frontend, packet, packetlen) < 0)
+				return POOL_END;
+		}
 	}
 
 	return POOL_CONTINUE;
empty-query.diff (2,048 bytes)

a.dushechkin

2017-08-14 13:23

reporter   ~0001648

Yes, the attached patch fixes the issue for me. Thank you.

t-ishii

2017-08-14 13:38

developer   ~0001649

Thank you for testing. The patch has been committed/pushed to 3.6 and 3.5 stable trees (only those versions are affected by the bug).
The issue resolved now.

Issue History

Date Modified Username Field Change
2017-08-11 15:30 a.dushechkin New Issue
2017-08-11 19:37 t-ishii Assigned To => t-ishii
2017-08-11 19:37 t-ishii Status new => assigned
2017-08-11 19:40 t-ishii File Added: empty-query.diff
2017-08-11 19:40 t-ishii Note Added: 0001641
2017-08-11 19:41 t-ishii Status assigned => resolved
2017-08-11 19:41 t-ishii Target Version => 3.6.6
2017-08-11 19:43 administrator Status resolved => feedback
2017-08-11 19:43 administrator Resolution open => reopened
2017-08-14 13:23 a.dushechkin Note Added: 0001648
2017-08-14 13:23 a.dushechkin Status feedback => assigned
2017-08-14 13:38 t-ishii Note Added: 0001649
2017-08-14 13:39 t-ishii Status assigned => resolved