Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1a8WfX-0004ST-A8 for pgsql-bugs@arkaria.postgresql.org; Mon, 14 Dec 2015 17:12:15 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1a8WfW-0003JU-RN for pgsql-bugs@arkaria.postgresql.org; Mon, 14 Dec 2015 17:12:14 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1a8WfW-0003JH-51 for pgsql-bugs@postgresql.org; Mon, 14 Dec 2015 17:12:14 +0000 Received: from mail-pa0-x236.google.com ([2607:f8b0:400e:c03::236]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84) (envelope-from ) id 1a8WfS-0000I0-VV for pgsql-bugs@postgresql.org; Mon, 14 Dec 2015 17:12:12 +0000 Received: by pabur14 with SMTP id ur14so107104691pab.0 for ; Mon, 14 Dec 2015 09:12:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:subject:to:references:cc:from:message-id:date:user-agent :mime-version:in-reply-to:content-type:content-transfer-encoding; bh=xjBbsJoa3Wf95BhYFjW5eI2rF5YlHyO7nFFoFCqC5G4=; b=n7iXJmCJxsYrjAp08LR0cpf+mTKLb49Tqrl+9W8gJuqnUdYdXxJV4I80m2z2k+S2Pk b7UrM4KQbDyaVtFZRSM3LT8drws4LV8PgU+JUh2OMyIsVcRwIeHxBWU00imBbNOBkcb8 HvWVNZYRyZgagOx7/wZ2ZDjdZI9ndrXBMhkdQXOq4gutTT876DU0o7zibQGZDxmxqWec dzXo5lg4jXoq+083kRvJoeFHAeJpJqSlhiHjGYVof7MNJfK+UDfZTdaI8A086TJbVQ8h 09z/NpDjgNoDwHl+PzrePNuo/a5lKhfF5TRGzos4oZRpJNhBP594YZ4TJrdnn3WsW6a0 ASWw== X-Received: by 10.66.118.135 with SMTP id km7mr10467255pab.159.1450113129892; Mon, 14 Dec 2015 09:12:09 -0800 (PST) Received: from [192.168.1.115] (dsl-hkibrasgw1-58c38f-82.dhcp.inet.fi. [88.195.143.82]) by smtp.gmail.com with ESMTPSA id ux2sm28945204pac.46.2015.12.14.09.12.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 14 Dec 2015 09:12:08 -0800 (PST) Subject: Re: PQexec() hangs on OOM To: Michael Paquier , Amit Kapila References: <547480DE.4040408@vmware.com> <55FC501A.5000409@iki.fi> Cc: Oleksandr Shulgin , Tom Lane , Pg Bugs From: Heikki Linnakangas Message-ID: <566EF84F.1030206@iki.fi> Date: Mon, 14 Dec 2015 19:11:43 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Icedove/38.4.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -2.6 (--) 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 On 16/10/15 05:00, Michael Paquier wrote: > On Thu, Oct 15, 2015 at 11:28 PM, Amit Kapila wrote: >> On Sun, Oct 11, 2015 at 6:31 PM, Michael Paquier >> wrote: >>> >>> Yeah, this behavior is caused by this piece of code: >>> @@ -600,7 +601,9 @@ getRowDescriptions(PGconn *conn, int msgLength) >>> advance_and_error: >>> /* Discard unsaved result, if any */ >>> if (result && result != conn->result) >>> PQclear(result); >>> An idea may be to check for conn->result->resultStatus != >>> PGRES_FATAL_ERROR to concatenate correctly the error messages using >>> pqCatenateResultError. But just returning the first error encountered >>> as you mention would be more natural. So I updated the patch this way. I pushed the ParamDescription fix. I'm not quite sure on the details of the COPY patch. Do you remember what this change in PQexecFinish is for: > @@ -1991,6 +1995,9 @@ PQexecFinish(PGconn *conn) > * We have to stop if we see copy in/out/both, however. We will resume > * parsing after application performs the data transfer. > * > + * Stop if we are in copy mode and error has occurred, the pending results > + * will be discarded during next execution in PQexecStart. > + * > * Also stop if the connection is lost (else we'll loop infinitely). > */ > lastResult = NULL; > @@ -2020,6 +2027,11 @@ PQexecFinish(PGconn *conn) > result->resultStatus == PGRES_COPY_BOTH || > conn->status == CONNECTION_BAD) > break; > + else if ((conn->asyncStatus == PGASYNC_COPY_IN || > + conn->asyncStatus == PGASYNC_COPY_OUT || > + conn->asyncStatus == PGASYNC_COPY_BOTH) && > + result->resultStatus == PGRES_FATAL_ERROR) > + break; > } > > return lastResult; I don't immediately see why that's needed. I ran the little tester program I wrote earlier (http://www.postgresql.org/message-id/55FC501A.5000409@iki.fi), with and without that change, and it behaved the same. Also, when I modify my tester program so that when malloc fails, all subsequent mallocs fail too, I'm still getting the "another command is already in progress" error. The problem scenario is: 1. Application calls PQexec("COPY foo FROM STDIN") 2. getCopyStart sets conn->asyncStatus = PGASYNC_COPY_IN. 3. PQgetResult calls getCopyResult() but it fails with OOM. Now, libpq is already in PGASYNC_COPY_IN mode, but PQexec() returned NULL because of the OOM, so the application doesn't know that it's in copy mode. When the application calls PQexec() again, it fails with the "another command is already in progress" error. Let's see if we can fix that too, or if we should put that off to yet another patch. - Heikki -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs