Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bdJ3S-0006q7-Od for pgsql-hackers@arkaria.postgresql.org; Fri, 26 Aug 2016 15:28:26 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1bdJ3R-0000iF-SE for pgsql-hackers@arkaria.postgresql.org; Fri, 26 Aug 2016 15:28:25 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1bdJ23-0007d2-Vd for pgsql-hackers@postgresql.org; Fri, 26 Aug 2016 15:27:00 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1bdJ20-00067w-W5 for pgsql-hackers@postgresql.org; Fri, 26 Aug 2016 15:26:59 +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 u7QFQqCU018610; Fri, 26 Aug 2016 11:26:52 -0400 From: Tom Lane To: Robert Haas cc: "pgsql-hackers@postgresql.org" Subject: Re: PG_DIAG_SEVERITY and a possible bug in pq_parse_errornotice() In-reply-to: References: <11859.1472139831@sss.pgh.pa.us> <15203.1472145555@sss.pgh.pa.us> <23534.1472212411@sss.pgh.pa.us> <16610.1472222135@sss.pgh.pa.us> Comments: In-reply-to Robert Haas message dated "Fri, 26 Aug 2016 11:04:16 -0400" Date: Fri, 26 Aug 2016 11:26:52 -0400 Message-ID: <18609.1472225212@sss.pgh.pa.us> X-Pg-Spam-Score: -2.1 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org Robert Haas writes: > On Fri, Aug 26, 2016 at 10:35 AM, Tom Lane wrote: >> BTW, while I'm looking at this: what on god's green earth is >> ThrowErrorData doing copying the supplied data into edata->assoc_context? >> Surely it should be putting the data into the ErrorContext, where it's not >> going to get flushed before it can be reported? > Uh, well, perhaps I misinterpreted the comment in elog.h. It says this: > /* context containing associated non-constant strings */ > struct MemoryContextData *assoc_context; > That sure looks like it's saying that all of the pointers stored in > the ErrorData structure should be pointing into assoc_context, unless > they are constant. Indeed. The point is that every ErrorData in the errordata stack needs to, and does, have assoc_context = ErrorContext. This coding is blithely ignoring what errstart has set up and copying the data someplace else. In fact, it's pointlessly duplicating data that is *already* in the context of the source ErrorData. You should be imagining this action as being the reverse of CopyErrorData, ie copying some data back into the purview of elog.c, which is to say it should be in ErrorContext. Or in short, this has confused edata and newedata. Valid coding would be oldcontext = MemoryContextSwitchTo(newedata->assoc_context); rather than what is there. >> (Note that in the sole >> existing use-case, edata->assoc_context is going to have been set to >> CurrentMemoryContext by pq_parse_errornotice, and I see no good reason to >> assume that's very long-lived ... in fact, it looks like it's whatever >> happens to be active when ProcessInterrupts is called, which means there's >> probably a totally separate set of problems here having to do with >> potential leaks into long-lived contexts.) > Oops. Yes. I'm not quite sure what to do about this. It feels a tad wrong to use ErrorContext as the active context during HandleParallelMessages, but what else should we use? Maybe this needs its very own private context that we can reset after each use? >> I have little use for the name of that function either, as it's not >> necessarily going to "throw" anything. Maybe ReportErrorUsingData, >> or something like that? > I deliberately avoided that sort of terminology because it need not be > an ERROR. It can be, say, a NOTICE. It is definitely something that > is coming from an ErrorData but it need not be an ERROR. Right, but to me, "throw" generally means a transfer of control, which is exactly what this isn't going to do if the message is only a notice. regards, tom lane -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers