Received: from makus.postgresql.org ([98.129.198.125]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1T6Ahi-0001z6-Ah for pgsql-bugs@postgresql.org; Tue, 28 Aug 2012 01:34:54 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1T6Ahf-0007a4-Mr for pgsql-bugs@postgresql.org; Tue, 28 Aug 2012 01:34:53 +0000 Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.5/8.14.5) with ESMTP id q7S1Ynof014893; Mon, 27 Aug 2012 21:34:49 -0400 (EDT) From: Tom Lane To: Bruce Momjian cc: Ryan Kelly , pgsql-bugs@postgresql.org Subject: Re: [PATCH] Prevent hanging on unreachable hosts on startup In-reply-to: <20120827032741.GE28780@momjian.us> References: <20120105011730.GA26760@llserver.lakeliving.com> <3741.1325731017@sss.pgh.pa.us> <20120105142355.GB26760@llserver.lakeliving.com> <20120827032741.GE28780@momjian.us> Comments: In-reply-to Bruce Momjian message dated "Sun, 26 Aug 2012 23:27:41 -0400" Date: Mon, 27 Aug 2012 21:34:48 -0400 Message-ID: <14892.1346117688@sss.pgh.pa.us> X-Pg-Spam-Score: -2.1 (--) X-Archive-Number: 201208/209 X-Sequence-Number: 33933 Bruce Momjian writes: > Tom, can you comment on this patch because you commented on the previous > version? Thanks. Doesn't that provoke a pile of compiler warnings about local variables potentially being altered during longjmp? It sure looks pretty unsafe from here. It also fails to print any error message if a connection attempt is canceled. A bigger-picture question is just how safe it is to longjmp out of libpq partway through a connection attempt. At the very least, that's likely to leak an open socket and some memory. Maybe that doesn't matter too much for psql, but I'm not convinced. It seems fairly likely that internal state for libc (malloc), openssl, etc, could be left in a corrupt state if the interrupt happens at just the wrong time. (This didn't matter so much for the original proposal, where we'd just have been exiting psql anyway on failure. But if it's in \c then we want psql to still be operational after a failure.) We could perhaps dodge the longjmp safety question by using a PQconnectStartParams/PQconnectPoll loop. I'm not sure that provides 100% the same functionality --- in particular, I think it wouldn't allow interrupting out of a DNS name resolution delay. But it'd be less likely to result in strange crashes. regards, tom lane