Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1Tyrva-0003ZT-T9 for pgsql-bugs@arkaria.postgresql.org; Fri, 25 Jan 2013 22:39:19 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1TyrvZ-0005HG-QQ for pgsql-bugs@arkaria.postgresql.org; Fri, 25 Jan 2013 22:39:17 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TyrvY-0005HA-UJ for pgsql-bugs@postgresql.org; Fri, 25 Jan 2013 22:39:16 +0000 Received: from moutng.kundenserver.de ([212.227.17.10]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TyrvW-00081E-1B for pgsql-bugs@postgresql.org; Fri, 25 Jan 2013 22:39:16 +0000 Received: from anarazel.de (p5DDC4573.dip.t-dialin.net [93.220.69.115]) by mrelayeu.kundenserver.de (node=mreu0) with ESMTP (Nemesis) id 0M8dKp-1UtSr23zjH-00w7Yc; Fri, 25 Jan 2013 23:39:00 +0100 Received: by anarazel.de (Postfix, from userid 1000) id 2BB891C0177; Fri, 25 Jan 2013 23:38:59 +0100 (CET) Date: Fri, 25 Jan 2013 23:38:59 +0100 From: Andres Freund To: Tom Lane Cc: Sandro Santilli , pgsql-bugs@postgresql.org, peter_e@gmx.net Subject: Re: cache lookup failed from empty plpythonu function Message-ID: <20130125223859.GA8538@awork2.anarazel.de> References: <20130124140336.GJ3157@gnash> <20130124141751.GB21296@awork2.anarazel.de> <19721.1359045633@sss.pgh.pa.us> <20130125132025.GD4289@awork2.anarazel.de> <23521.1359151679@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <23521.1359151679@sss.pgh.pa.us> X-Provags-ID: V02:K0:AlZYoLe+izSWOBpOcYP905rS5LpgNzNx2ovElEKaww1 EBHzvu9zM3q1Le7b8tFs5PwEVJYS5hr0SB3eak8kOzfuFJkWTt PJnJOJgC5cOdnMtS/Y+8ILZghkE9HHEix5dBWpQpdiy0LC1Yuu 7id4kI+l9wR1lGgmTVmXrnsFIFR22MV1qOw2X31Y48vFTqbp0w 5rTVnrFld6cM4dmVppuwuXlW3KJOXzsgosdFYW5DQLcacKpPp3 XP6txRpnANfHHRTpwzxZxN4LWWkXwPzOOJH6Z2uWLmxlwjAiOl pM1Fn45KMLGa0233M3RM9w4HBhzxpqcy2dx6xeRDq2pwFNXYCi w7NJru3OeuUOLNCq6Tc6iDa6elaBjrq8tKOIlMAE4 X-Pg-Spam-Score: -1.9 (-) 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 2013-01-25 17:07:59 -0500, Tom Lane wrote: > Andres Freund writes: > > The bug got introduced in 46211da1b84bc3537e799ee1126098e71c2428e8 which > > interestingly says "Using HTABs instead of Python dictionaries makes > > error recovery easier, and allows for procedures to be cached based on > > their OIDs, not their names." - but the caching seems to always have > > used ("%u_%u", fn_oid, tgreloid) as its key which explains why the bug > > didn't exist back then. > > > Anyway, as far as I can see only 9.1 upwards are affected. > > Patch applied with some editorialization, mostly cosmetic but one thing > not so much: you introduced uninitialized-variable hazards into > PLy_procedure_get, since if use_cache is false then found, entry, and > proc wouldn't get set up. Gah. Now I am pissed at myself. I thought I had initialized 'found' to false which should be enough. > Neither version of gcc I tried complained about this, and I assume yours > didn't either, which is a bit annoying/scary. I wonder whether the > "volatile" marker prevents that? I think the control flow is just to complex for gcc, it probably cannot trace anything across a setjmp() althout it theoretically should be possible given the failure is in the branch that is executed unconditionally. Given that the real culprit is 'found' I don't think its the volatiles. > BTW, it seems to me that there is another bug in PLy_procedure_get, > which is that it's not thinking about recursive use of a procedure. > Consider > > call f > > ... somebody updates f's pg_proc tuple > > ... recursively call f > > At this point PLy_procedure_get will decide the cache entry is obsolete > and happily trash the procedure data that the outer call is still using. > We ran into this long ago with plpgsql and fixed it by adding > reference-counting logic. Probably the same needs to be done here. > > There are probably not that many people trying to use plpython functions > in such a way (note the recursion would have to happen via a SPI query, > not directly within Python). But still... I am afraid youre right. It seems ugly that all pl's have to reinvent that kind of cache + invalidation logic. I am e.g. not sure they go far enough in invalidating stuff like parameter types & io functions. Greetings, Andres Freund -- Andres Freund http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Training & Services -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs