Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TzyWi-0000Rp-0Y for pgsql-bugs@arkaria.postgresql.org; Mon, 28 Jan 2013 23:54:12 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1TzyWh-0004Cj-0s for pgsql-bugs@arkaria.postgresql.org; Mon, 28 Jan 2013 23:54:11 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TzyWg-0004Cd-0y for pgsql-bugs@postgresql.org; Mon, 28 Jan 2013 23:54:10 +0000 Received: from [2404:130:0:10::40:2] (helo=mail.catalyst.net.nz) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TzyWb-0006uo-60 for pgsql-bugs@postgresql.org; Mon, 28 Jan 2013 23:54:09 +0000 Received: from localhost (localhost [127.0.0.1]) by mail.catalyst.net.nz (Postfix) with ESMTP id 1B58533283; Tue, 29 Jan 2013 12:54:00 +1300 (NZDT) X-Virus-Scanned: Debian amavisd-new at catalyst.net.nz Received: from mail.catalyst.net.nz ([127.0.0.1]) by localhost (bertrand.catalyst.net.nz [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id lu5izLyFCN1s; Tue, 29 Jan 2013 12:53:56 +1300 (NZDT) Received: from [IPv6:2404:130:0:1000:89f:3dd1:3f58:4acb] (unknown [IPv6:2404:130:0:1000:89f:3dd1:3f58:4acb]) (Authenticated sender: mark.kirkwood) by mail.catalyst.net.nz (Postfix) with ESMTPSA id 0499C3300E; Tue, 29 Jan 2013 12:53:56 +1300 (NZDT) Message-ID: <51071083.6010801@catalyst.net.nz> Date: Tue, 29 Jan 2013 12:57:55 +1300 From: Mark Kirkwood User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130106 Thunderbird/17.0.2 MIME-Version: 1.0 To: Tom Lane CC: pgsql-bugs@postgresql.org, Joe Conway Subject: Re: PL/R Median Busts Commit (Postgres 9.1.6 + plr 8.3.0.13 on Ubuntu 12.10 64 bit) References: <5100B6B2.8030408@catalyst.net.nz> <51014FCB.30601@joeconway.com> <5101A3DA.5080507@catalyst.net.nz> <5101A47D.6050508@catalyst.net.nz> <25545.1359062304@sss.pgh.pa.us> <5101A7D1.6040703@catalyst.net.nz> <25945.1359063403@sss.pgh.pa.us> <5101B8AF.3090307@catalyst.net.nz> <28888.1359072381@sss.pgh.pa.us> <5101D43F.90102@catalyst.net.nz> <29635.1359074960@sss.pgh.pa.us> <5101D849.5050705@catalyst.net.nz> <5106EDA0.4050307@catalyst.net.nz> In-Reply-To: <5106EDA0.4050307@catalyst.net.nz> Content-Type: multipart/mixed; boundary="------------020101070201010207000807" X-Host-Lookup-Failed: Reverse DNS lookup failed for 2404:130:0:10::40:2 (failed) X-Pg-Spam-Score: -1.1 (-) 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 This is a multi-part message in MIME format. --------------020101070201010207000807 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit On 29/01/13 10:29, Mark Kirkwood wrote: > On 25/01/13 13:56, Mark Kirkwood wrote: >> On 25/01/13 13:49, Tom Lane wrote: >>> Mark Kirkwood writes: >>>> On 25/01/13 13:06, Tom Lane wrote: >>>>> Unless libR can be coerced into not screwing up our signal handlers, >>>>> I'd say that PL/R is broken beyond repair. That would be >>>>> unfortunate. >>> >>>> It looks like Joe has run into something similar with libR stealing >>>> SIGINT, he reinstalls it. A simple patch along the same lines for >>>> SIGUSR1 (attached) seems to fix the issue. >>> >>> This certainly is not good enough, for either signal. What happens if >>> the signal arrives while libR still has control? These things being >>> asynchronous with respect to the receiving backend, we certainly can't >>> assume that that won't happen. >>> >>> Why does libR think it should be messing with these handlers in the >>> first place? >>> >>> >> >> Agreed - I will see if I can work out why. >> > > > Looking at the R source (which reminds me of Postgres, nice, clear > code...), I saw quite a bit of code involving signal handlers - and > nothing along the lines of "don't set them up if you are in embedded > mode". So clearly more investigation is needed, and we really need to > take this up on the R mailing list I think. Joe - is this something > you would like to do? I am happy do it, but my knowledge of R is > measured in hours... > > Like a dog with a bone - sometimes it's hard to let go... given the quite readable nature of the R source I managed to find what I *think* is the "don't do R signals switch" (which I'd obviously missed before). Making use of this seems to fix the original bug - and possibly the SIGINT stealing too. Patch attached to set the variable (R_SignalHandlers = 0), and remove the SIGINT workaround. Cheers Mark --------------020101070201010207000807 Content-Type: text/x-patch; name="plr.c-no-r-sig-handlers.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="plr.c-no-r-sig-handlers.diff" *** plr.c.orig 2011-08-30 10:42:56.000000000 +1200 --- plr.c 2013-01-29 12:56:53.995936063 +1300 *************** *** 31,37 **** * plr.c - Language handler and support functions */ #include "plr.h" - #include "libpq/pqsignal.h" PG_MODULE_MAGIC; --- 31,36 ---- *************** *** 369,374 **** --- 368,378 ---- atexit(plr_atexit); /* + * Try to stop R using its own signal handlers + */ + R_SignalHandlers = 0; + + /* * When initialization fails, R currently exits. Check the return * value anyway in case this ever gets fixed */ *************** *** 392,401 **** R_Interactive = false; #endif - /* - * R seems to try to steal SIGINT in recent releases, so steal it back - */ - pqsignal(SIGINT, StatementCancelHandler); /* cancel current query */ plr_pm_init_done = true; } --- 396,401 ---- --------------020101070201010207000807 Content-Type: text/plain Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs --------------020101070201010207000807--