From 41bf6d767f17d47ed2d87a53ee42c4779333341b Mon Sep 17 00:00:00 2001 From: Tatsuo Ishii Date: Fri, 18 Jul 2014 16:37:56 +0900 Subject: [PATCH] Fix reset query stuck problem. It is reported that reset query (DISCARD ALL etc.) occasionally does not finish and pgpool child remain waiting for reply from backend thus client cannot connect to pgpool (for example http://www.pgpool.net/mantisbt/view.php?id=107). The cause of problem is not identified yet but if client suddenly closes connection to pgpool in the middle of query processing, backend may not accept the reset queries because they are not ready for query. The fix is, if frontend closes connection in unexpected way, query process loop immediately returns with new state: POOL_END_WITH_FRONTEND_ERROR and pgpool closes connection to PostgreSQL then goes back to new connection request waiting loop. --- child.c | 5 ++++- pool.h | 3 ++- pool_proto_modules.c | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/child.c b/child.c index 63f989719..c7b15abb1 100644 --- a/child.c +++ b/child.c @@ -384,12 +384,15 @@ void do_child(int unix_fd, int inet_fd) { /* client exits */ case POOL_END: + case POOL_END_WITH_FRONTEND_ERROR: /* * do not cache connection if: + * frontend abnormally exits or * pool_config->connection_cahe == 0 or * database name is template0, template1, postgres or regression */ - if (pool_config->connection_cache == 0 || + if (status == POOL_END_WITH_FRONTEND_ERROR || + pool_config->connection_cache == 0 || !strcmp(sp->database, "template0") || !strcmp(sp->database, "template1") || !strcmp(sp->database, "postgres") || diff --git a/pool.h b/pool.h index afc088c21..e772d2454 100644 --- a/pool.h +++ b/pool.h @@ -6,7 +6,7 @@ * pgpool: a language independent connection pool server for PostgreSQL * written by Tatsuo Ishii * - * Copyright (c) 2003-2012 PgPool Global Development Group + * Copyright (c) 2003-2014 PgPool Global Development Group * * Permission to use, copy, modify, and distribute this software and * its documentation for any purpose and without fee is hereby @@ -78,6 +78,7 @@ typedef enum { POOL_CONTINUE = 0, POOL_IDLE, POOL_END, + POOL_END_WITH_FRONTEND_ERROR, POOL_ERROR, POOL_FATAL, POOL_DEADLOCK diff --git a/pool_proto_modules.c b/pool_proto_modules.c index c82173f1c..69aca1cb9 100644 --- a/pool_proto_modules.c +++ b/pool_proto_modules.c @@ -2184,7 +2184,7 @@ POOL_STATUS ProcessFrontendResponse(POOL_CONNECTION *frontend, if (pool_read(frontend, &fkind, 1) < 0) { pool_log("ProcessFrontendResponse: failed to read kind from frontend. frontend abnormally exited"); - return POOL_END; + return POOL_END_WITH_FRONTEND_ERROR; } pool_debug("ProcessFrontendResponse: kind from frontend %c(%02x)", fkind, fkind); -- 2.39.5