Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TyrRR-00023q-Do for pgsql-bugs@arkaria.postgresql.org; Fri, 25 Jan 2013 22:08:09 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1TyrRQ-0000kw-Qk for pgsql-bugs@arkaria.postgresql.org; Fri, 25 Jan 2013 22:08:08 +0000 Received: from makus.postgresql.org ([98.129.198.125]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TyrRP-0000k8-Qy for pgsql-bugs@postgresql.org; Fri, 25 Jan 2013 22:08:07 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TyrRO-0000V0-8H for pgsql-bugs@postgresql.org; Fri, 25 Jan 2013 22:08:07 +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 r0PM7xKr023522; Fri, 25 Jan 2013 17:07:59 -0500 (EST) From: Tom Lane To: Andres Freund cc: Sandro Santilli , pgsql-bugs@postgresql.org, peter_e@gmx.net Subject: Re: cache lookup failed from empty plpythonu function In-reply-to: <20130125132025.GD4289@awork2.anarazel.de> References: <20130124140336.GJ3157@gnash> <20130124141751.GB21296@awork2.anarazel.de> <19721.1359045633@sss.pgh.pa.us> <20130125132025.GD4289@awork2.anarazel.de> Comments: In-reply-to Andres Freund message dated "Fri, 25 Jan 2013 14:20:25 +0100" Date: Fri, 25 Jan 2013 17:07:59 -0500 Message-ID: <23521.1359151679@sss.pgh.pa.us> 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 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. 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? 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... 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