View Issue Details

IDProjectCategoryView StatusLast Update
0000021Pgpool-IIBugpublic2012-10-02 10:14
ReporterelisechiangAssigned Tot-ishii 
PriorityimmediateSeveritymajorReproducibilityalways
Status resolvedResolutionopen 
Platformpgpool II 3.2.0OScentosOS Version6.2
Product Version 
Target VersionFixed in Version 
Summary0000021: pgpool-II 3.2.0 cannot execute sql through jdbc
DescriptionHi!
I can usr pgAdmin III acess pgpool, but I cannot execute sql on pgpool through jdbc.


The following message is the jdbc return message and please see the attached pgpool.log file. Thanks.

Size in bytes: 31
Headers size in bytes: 0
Body size in bytes: 31
Response code: ut 08006 0
Response message: org.postgresql.util.PSQLException: An I/O error occured while sending to the backend

Response headers:
org.postgresql.jdbc4.Jdbc4Connection@7b543662

ContentType: text/plain
DataEncoding: UTF-8
Additional Informationpostgresql-8.4.12-1.el6_2.x86_64 2 backends ,db locale : zh_TW.UTF-8
pgpool II 3.2.0
jdbc driver : postgresql-8.4-703.jdbc4.jar
TagsNo tags attached.

Activities

elisechiang

2012-08-17 16:31

reporter  

pgpool.log (16,554 bytes)

t-ishii

2012-08-24 15:58

developer   ~0000052

If you are operating in replication mode, I think it was already fixed in 3.1-STABLE tree.
http://git.postgresql.org/gitweb/?p=pgpool2.git;a=commit;h=479e9d1416ff0294519e9155084bc1d60c75c850

Please try it.

gowthamanb

2012-09-20 23:00

reporter   ~0000084

i have the same issue in 3.2, 3.1-STABLE works though

t-ishii

2012-09-20 23:45

developer   ~0000085

Oops. What I meant was 3.2-STABLE tree, not 3.1-STABLE. Please try 3.2-STABLE.

gowthamanb

2012-09-21 01:15

reporter   ~0000086

I just tried with 3.2-STABLE but same error persists, however 3.1-STABLE still works

t-ishii

2012-09-21 13:56

developer   ~0000087

Can someone please upload pgpool-II 3.1 log with debug mode enabled? 3.2.0 log has been already uploaded and I want to compare them.

gowthamanb

2012-09-22 00:27

reporter  

pgpool-1.log (2,064,606 bytes)

gowthamanb

2012-09-22 00:29

reporter   ~0000088

i uploaded pgpool-1.log pardon me for the size, the difference i observed in in 3.2 the exception gets thrown even while the query is being executed

t-ishii

2012-09-23 20:22

developer   ~0000089

I think you turn on log_per_node_statement with pgpool-II 3.2. If you turn it off , do you still see the exception?

gowthamanb

2012-09-23 22:15

reporter   ~0000090

the problem is with cache, i tried both memcached and shmem,

if i turn cache on, it doesn't work

if i turn off the cache, 3.2 works perfect

t-ishii

2012-09-29 20:55

developer   ~0000101

Ok. I seem to find the problem. Parse(), which is in charge of processing parse message, is given parse message packet contents as an argument. Unfortunately the argument is in pool_read2 buffer, which can be modified while Parse() is doing on memory query cache treatment. Thus subsequent process in Parse() looks into unexpected data and segfaults. If memory cache enabled, this does not happen.
The fix is copying packet contents before calling Parse(). Please try attached patch(memqcache.patch).

t-ishii

2012-09-29 20:56

developer  

memqcache.patch (2,913 bytes)
diff --git a/pool_proto_modules.c b/pool_proto_modules.c
index 733525b..ed186a6 100644
--- a/pool_proto_modules.c
+++ b/pool_proto_modules.c
@@ -2352,7 +2352,8 @@ POOL_STATUS ProcessFrontendResponse(POOL_CONNECTION *frontend,
 									POOL_CONNECTION_POOL *backend)
 {
 	char fkind;
-	char *contents = NULL;
+	char *bufp = NULL;
+	char *contents;
 	POOL_STATUS status;
 	int len;
 	POOL_SESSION_CONTEXT *session_context;
@@ -2382,15 +2383,15 @@ POOL_STATUS ProcessFrontendResponse(POOL_CONNECTION *frontend,
 			return POOL_END;
 		len = ntohl(len) - 4;
 		if (len > 0)
-			contents = pool_read2(frontend, len);
+			bufp = pool_read2(frontend, len);
 	}
 	else
 	{
 		if (fkind != 'F')
-			contents = pool_read_string(frontend, &len, 0);
+			bufp = pool_read_string(frontend, &len, 0);
 	}
 
-	if (len > 0 && contents == NULL)
+	if (len > 0 && bufp == NULL)
 		return POOL_END;
 
 	if (fkind != 'S' && pool_is_ignore_till_sync())
@@ -2406,6 +2407,19 @@ POOL_STATUS ProcessFrontendResponse(POOL_CONNECTION *frontend,
 
 	pool_unset_doing_extended_query_message();
 
+	/*
+	 * Alloate buffer and copy the packet contents.  Because inside
+	 * these protocol modules, pool_read2 maybe called and modify its
+	 * buffer contents.
+	 */
+	contents = malloc(len);
+	if (contents == NULL)
+	{
+		pool_error("ProcessFrontendResponse: cannot allocate memory. request size:%d", len);
+		return POOL_ERROR;
+	}
+	memcpy(contents, bufp, len);
+
 	switch (fkind)
 	{
 		POOL_QUERY_CONTEXT *query_context;
@@ -2415,6 +2429,7 @@ POOL_STATUS ProcessFrontendResponse(POOL_CONNECTION *frontend,
 		POOL_MEMORY_POOL *old_context;
 
 		case 'X':	/* Terminate */
+			free(contents);
 			return POOL_END;
 
 		case 'Q':	/* Query */
@@ -2475,6 +2490,7 @@ POOL_STATUS ProcessFrontendResponse(POOL_CONNECTION *frontend,
 			if (!query_context)
 			{
 				pool_error("ProcessFrontendResponse: pool_init_query_context failed");
+				free(contents);
 				return POOL_END;
 			}
 			old_context = pool_memory_context_switch_to(query_context->memory_context);
@@ -2507,6 +2523,7 @@ POOL_STATUS ProcessFrontendResponse(POOL_CONNECTION *frontend,
 			pool_error("ProcessFrontendResponse: unknown message type %c(%02x)", fkind, fkind);
 			status = POOL_ERROR;
 	}
+	free(contents);
 
 	if (status != POOL_CONTINUE)
 		status = POOL_ERROR;
diff --git a/pool_query_context.c b/pool_query_context.c
index ee95a2a..6dbe397 100644
--- a/pool_query_context.c
+++ b/pool_query_context.c
@@ -95,7 +95,7 @@ void pool_start_query(POOL_QUERY_CONTEXT *query_context, char *query, int len, N
 		session_context = pool_get_session_context();
 		query_context->original_length = len;
 		query_context->rewritten_length = -1;
-		query_context->original_query = query;
+		query_context->original_query = pstrdup(query);
 		query_context->rewritten_query = NULL;
 		query_context->parse_tree = node;
 		query_context->virtual_master_node_id = my_master_node_id;
memqcache.patch (2,913 bytes)

Issue History

Date Modified Username Field Change
2012-08-17 16:31 elisechiang New Issue
2012-08-17 16:31 elisechiang File Added: pgpool.log
2012-08-24 15:58 t-ishii Note Added: 0000052
2012-08-24 15:58 t-ishii Assigned To => t-ishii
2012-08-24 15:58 t-ishii Status new => assigned
2012-09-20 23:00 gowthamanb Note Added: 0000084
2012-09-20 23:45 t-ishii Note Added: 0000085
2012-09-21 01:15 gowthamanb Note Added: 0000086
2012-09-21 13:56 t-ishii Note Added: 0000087
2012-09-22 00:27 gowthamanb File Added: pgpool-1.log
2012-09-22 00:29 gowthamanb Note Added: 0000088
2012-09-23 20:22 t-ishii Note Added: 0000089
2012-09-23 22:15 gowthamanb Note Added: 0000090
2012-09-29 20:55 t-ishii Note Added: 0000101
2012-09-29 20:56 t-ishii File Added: memqcache.patch
2012-10-02 10:14 t-ishii Status assigned => resolved