From: | Jacob Champion <jacob(dot)champion(at)enterprisedb(dot)com> |
---|---|
To: | PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org> |
Cc: | Daniel Gustafsson <daniel(at)yesql(dot)se>, alvherre(at)alvh(dot)no-ip(dot)org, Andrew Dunstan <andrew(at)dunslane(dot)net>, Michael Paquier <michael(at)paquier(dot)xyz> |
Subject: | Support json_errdetail in FRONTEND builds |
Date: | 2024-03-12 18:43:23 |
Message-ID: | CAOYmi+mWdTd6ujtyF7MsvXvk7ToLRVG_tYAcaGbQLvf=N4KrQw@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
Hello,
Both the incremental JSON [1] and OAuth [2] patchsets would be
improved by json_errdetail(), which was removed from FRONTEND builds
in b44669b2ca:
> The routine providing a detailed error message based on the error code
> is made backend-only, the existing code being unsafe to use in the
> frontend as the error message may finish by being palloc'd or point to a
> static string, so there is no way to know if the memory of the message
> should be pfree'd or not.
Attached is a patch to undo this, by attaching any necessary
allocations to the JsonLexContext so the caller doesn't have to keep
track of them.
This is based on the first patch of the OAuth patchset, which
additionally needs json_errdetail() to be safe to use from libpq
itself. Alvaro pointed out offlist that we don't have to go that far
to re-enable this function for the utilities, so this patch is a sort
of middle ground between what we have now and what OAuth implements.
(There is some additional minimization that could be done to this
patch, but I'm hoping to keep the code structure consistent between
the two, if the result is acceptable.)
Two notes that I wanted to point out explicitly:
- On the other thread, Daniel contributed a destroyStringInfo()
counterpart for makeStringInfo(), which is optional but seemed useful
to include here.
- After this patch, if a frontend client calls json_errdetail()
without calling freeJsonLexContext(), it will leak memory.
Thanks,
--Jacob
[1] https://www.postgresql.org/message-id/682c8fff-355c-a04f-57ac-81055c4ccda8%40dunslane.net
[2] https://www.postgresql.org/message-id/CAOYmi%2BkKNZCL7uz-LHyBggM%2BfEcf4285pFWwm7spkUb8irY7mQ%40mail.gmail.com
Attachment | Content-Type | Size |
---|---|---|
0001-common-jsonapi-support-json_errdetail-in-FRONTEND.patch | application/octet-stream | 11.0 KB |
From | Date | Subject | |
---|---|---|---|
Next Message | Dean Rasheed | 2024-03-12 18:43:27 | Broken EXPLAIN output for SubPlan in MERGE |
Previous Message | Alvaro Herrera | 2024-03-12 18:28:40 | Re: [EXTERNAL] Re: Add non-blocking version of PQcancel |