From d3d8f8bda7c734ccdfac7e2049ea9613d6059507 Mon Sep 17 00:00:00 2001 From: Tatsuo Ishii Date: Sat, 25 Mar 2006 08:43:52 +0000 Subject: [PATCH] Check startup packet is identical before reusing existing connection. even if user/database/major are same, OPTION and other data might be different. One of such an example is, psql/JDBC 8.1 connects one and another. --- child.c | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/child.c b/child.c index 6ae71da..4fb8dbb 100644 --- a/child.c +++ b/child.c @@ -82,6 +82,7 @@ void do_child(int unix_fd, int inet_fd) static int connected; int connections_count = 0; /* used if child_max_connections > 0 */ int first_ready_for_query_received; /* for master/slave mode */ + int found; pool_debug("I am %d", getpid()); @@ -220,7 +221,37 @@ void do_child(int unix_fd, int inet_fd) first_ready_for_query_received = 0; /* for master/slave mode */ /* look for existing connection */ - if ((backend = pool_get_cp(sp->user, sp->database, sp->major)) == NULL) + found = 0; + backend = pool_get_cp(sp->user, sp->database, sp->major); + + if (backend != NULL) + { + found = 1; + + /* existing connection associated with same user/database/major found. + * however we should make sure that the startup packet contents identical. + * OPTION data and others might be different. + */ + if (sp->len != backend->slots[0]->sp->len) + { + pool_debug("pool_process_query: connection exists but startup packet length is not identical"); + found = 0; + } + else if(memcmp(sp->startup_packet, backend->slots[0]->sp->startup_packet, sp->len) != 0) + { + pool_debug("pool_process_query: connection exists but startup packet contents is not identical"); + found = 0; + } + + if (found == 0) + { + /* we need to discard existing connection since startup packet is different */ + pool_discard_cp(sp->user, sp->database, sp->major); + backend = NULL; + } + } + + if (backend == NULL) { /* create a new connection to backend */ connection_reuse = 0; -- 2.39.5