Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VpjX9-000802-Q8 for pgsql-bugs@arkaria.postgresql.org; Sun, 08 Dec 2013 18:56:51 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1VpjX8-0005ik-Vb for pgsql-bugs@arkaria.postgresql.org; Sun, 08 Dec 2013 18:56:51 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VpjX7-0005hL-FA for pgsql-bugs@postgresql.org; Sun, 08 Dec 2013 18:56:49 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VpjX5-0007AZ-8Z for pgsql-bugs@postgresql.org; Sun, 08 Dec 2013 18:56:49 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id rB8Iuifa015211; Sun, 8 Dec 2013 13:56:44 -0500 From: Tom Lane To: Peter Geoghegan cc: pgsql-bugs@postgresql.org Subject: Re: PQclientEncoding() returns -1, resulting in possible assertion failure in psql In-reply-to: <14465.1386526658@sss.pgh.pa.us> References: <14465.1386526658@sss.pgh.pa.us> Comments: In-reply-to Tom Lane message dated "Sun, 08 Dec 2013 13:17:38 -0500" Date: Sun, 08 Dec 2013 13:56:44 -0500 Message-ID: <15210.1386529004@sss.pgh.pa.us> X-Pg-Spam-Score: -2.0 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org I wrote: > Peter Geoghegan writes: >> If the call to PQclientEncoding() from processSQLNamePattern() (plus >> probably from other places) gets an encoding of -1, (called when we >> "\df+ somefunc" after the server is gone - you may have to do it >> twice), that can be passed down to PQmblen(), which will in turn pass >> that value to pg_encoding_mblen(), which doesn't expect it. > A simple fix might be to return SQL_ASCII not -1. I don't think the > -1 behavior is documented or relied on anywhere, is it? I looked at this a bit more closely and it seems to be a legitimate fix. I would also suggest that we remove the connection status check; there is no very good reason to forget what we knew about the encoding the moment the connection drops. So something like int PQclientEncoding(const PGconn *conn) { - if (!conn || conn->status != CONNECTION_OK) - return -1; + if (!conn) + return PG_SQL_ASCII; return conn->client_encoding; } A compromise that would probably fix the problem for psql, if not other places, would be to just remove the status check (ie, first line of above diff but not second). That might be the thing to do if people are afraid to change the behavior this much in back branches. I would argue however that the documentation nowhere suggests that PQclientEncoding can return a bogus encoding ID, so this is more likely to be a bug fix than a new bug for other programs as well. Also, it looks to me like there are probably other corner cases anyway where you can get PG_SQL_ASCII rather than the actual encoding, because that's how we initialize conn->client_encoding ... regards, tom lane -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs