pgpool2.git / summary / log / commit / refs
commit 4d91196df63ab34ac6567cfd793134e160680c9d
Author: Tatsuo Ishii <ishii@postgresql.org>
Date: Thu Jun 21 23:42:08 2012 +0000
Fix segfault in the case on memory query cache is enabled and PHP PDO
used. Actually this is not specific for PDO: PDO sends Sync message
right after Parse. Pgpool is confused because
pool_handle_query_cache() is called within ReadyForQuery() in this
case. Solution is, checking query_context->query_w_hex. If it is
NULL, then Bind message has not been sent yet.
Here is the small PDO script to reproduce the problem just F.Y.I.
<?php
function db() {
$db = new PDO("pgsql:host=localhost;port=11002;dbname=test");
return $db;
}
$n = 1;
for($i=0;$i < $n;$i++)
{
$db[$i] = db();
$stmt = $db[$i]->prepare("SELECT :num::int");
$stmt->execute(array(':num' => $i));
print_r($stmt->fetch());
//sleep(1);
$db[$i] = NULL;
echo date(DATE_RFC822);
}
// sleep(300);
?>
pool_proto_modules.c | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)
diff --git a/pool_proto_modules.c b/pool_proto_modules.c
index 7817ae99e..cf208addf 100644
--- a/pool_proto_modules.c
+++ b/pool_proto_modules.c
@@ -1725,10 +1725,21 @@ POOL_STATUS ReadyForQuery(POOL_CONNECTION *frontend,
/* Memory cache enabled? */
if (cache_commit && pool_config->memory_cache_enabled)
{
+ /* If we are doing extended query and the state is after EXECUTE,
+ * then we can commit cache.
+ * We check latter condition by looking at query_context->query_w_hex.
+ * This check is neccessary for certain flame work such as PHP PDO.
+ * It sends Sync message right after PARSE and it produces
+ * "Ready for query" message from backend.
+ */
if (pool_is_doing_extended_query_message())
{
- pool_handle_query_cache(backend, session_context->query_context->query_w_hex, node, state);
- free(session_context->query_context->query_w_hex); // malloced in Execute().
+ if (session_context->query_context->query_w_hex)
+ {
+ pool_handle_query_cache(backend, session_context->query_context->query_w_hex, node, state);
+ free(session_context->query_context->query_w_hex);
+ session_context->query_context->query_w_hex = NULL;
+ }
}
else
{
[parent: 50a10bfc45db]