Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1aMBu8-0004tG-KH for pgsql-hackers@arkaria.postgresql.org; Thu, 21 Jan 2016 09:51:48 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1aMBu8-0007ck-0F for pgsql-hackers@arkaria.postgresql.org; Thu, 21 Jan 2016 09:51:48 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1aMBsm-0004rh-JA for pgsql-hackers@postgresql.org; Thu, 21 Jan 2016 09:50:24 +0000 Received: from wagner.pp.ru ([178.63.209.18] helo=mx.wagner.pp.ru) by magus.postgresql.org with esmtp (Exim 4.84) (envelope-from ) id 1aMBsj-0004IJ-Ez for pgsql-hackers@postgresql.org; Thu, 21 Jan 2016 09:50:24 +0000 Received: from mail.wagner.pp.ru (unknown [192.168.217.132]) by mx.wagner.pp.ru (Postfix) with ESMTP id D8FE3486189 for ; Thu, 21 Jan 2016 12:49:11 +0300 (MSK) Received: from fafnir.local.vm (newmail.postgrespro.ru [93.174.131.138]) by mail.wagner.pp.ru (Postfix) with ESMTPSA id E37F420025 for ; Thu, 21 Jan 2016 12:49:09 +0300 (MSK) Date: Thu, 21 Jan 2016 12:49:09 +0300 From: Victor Wagner To: pgsql-hackers@postgresql.org Subject: Re: Patch: Implement failover on libpq connect level. Message-ID: <20160121124909.7fa66dab@fafnir.local.vm> In-Reply-To: References: <20150818041850.GA5092@wagner.pp.ru> <20151014104151.GA6744@wagner.pp.ru> <562E8C55.9030409@gmx.net> <20151028111839.6e73c68a@fafnir> <56327381.5040108@gmx.net> <56379A44.9080609@gmx.net> <20151105151235.GA21434@wagner.pp.ru> <20151106153807.GA6104@alvherre.pgsql> <20151109124404.1af6ba0c@fafnir> <5665EB79.9070805@enterprisedb.com> <20151210075419.6c9b7ca4@wagnner.wagner.home> <56780A3D.2090609@sigaev.ru> <20151221175013.644535cd@fafnir.local.vm> X-Mailer: Claws Mail 3.13.0 (GTK+ 2.24.25; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org On Tue, 19 Jan 2016 14:34:54 +0000 Thom Brown wrote: > The segfault issue I originally reported now appears to be resolved. > > But now I have another one: > > psql > 'postgresql://thom@127.0.0.1:5530,127.0.0.1:5531,127.0.0.1:5532,127.0.0.1:5533/postgres?hostorder=random&readonly=1&failover_timeout=5' > -c 'show port' > > Segmentation fault This segfault appears to be a simple programming error. which comes out only when we need to retry address list (which happens when no node is available at the time of first scan) There is code which prevents random hostorder to connect same node twice a row while (current != NULL) { if (current == conn->addr_cur) { current = current->ai_next; } count++; if ((rand()&0xffff) < 0x10000 / count) { choice = current; } current = current->ai_next; } There should be continue; after first current = current->ai_next; > This is where no nodes are available. If I remove hostorder=random, > or replace it with hostorder=sequential, it doesn't segfault. > However, it then tries to connect to PGHOST on PGPORT repeatedly, even > if I bring up one of the nodes it should be looking for. Not only > this, but it seems to do it forever if failover_timeout is greater > than 0. But this turns out to be more complicated matter, so I'm not ready to provide next version of patch yet. -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers