pg.ddx.io pgsql-committers@postgresql.org mailing list archive
help / color / mirror / Atom feedpgsql: Fix connection leak in DROP SUBSCRIPTION command.
8+ messages / 5 participants
[nested] [flat]
Commits from this thread:
2017-03-08 77d21970ae Fix connection leak in DROP SUBSCRIPTION command, take 2.
* pgsql: Fix connection leak in DROP SUBSCRIPTION command.
@ 2017-02-21 18:36 Fujii Masao <fujii@postgresql.org>
0 siblings, 1 reply; 8+ messages in thread
From: Fujii Masao @ 2017-02-21 18:36 UTC (permalink / raw)
To: pgsql-committers
Fix connection leak in DROP SUBSCRIPTION command.
Previously the command forgot to close the connection to the publisher
when it failed to drop the replication slot.
Branch
------
master
Details
-------
http://git.postgresql.org/pg/commitdiff/898a792eb8283e31efc0b6fcbc03bbcd5f7df667
Modified Files
--------------
src/backend/commands/subscriptioncmds.c | 4 ++++
1 file changed, 4 insertions(+)
--
Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-committers
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: pgsql: Fix connection leak in DROP SUBSCRIPTION command.
@ 2017-02-21 19:12 Tom Lane <tgl@sss.pgh.pa.us>
parent: Fujii Masao <fujii@postgresql.org>
0 siblings, 1 reply; 8+ messages in thread
From: Tom Lane @ 2017-02-21 19:12 UTC (permalink / raw)
To: Fujii Masao <fujii@postgresql.org>; +Cc: pgsql-committers
Fujii Masao <fujii@postgresql.org> writes:
> Fix connection leak in DROP SUBSCRIPTION command.
> Previously the command forgot to close the connection to the publisher
> when it failed to drop the replication slot.
If there's a bug here, this seems like an extremely unreliable way of
fixing it. What if an error gets thrown before you reach that ereport?
In other words, this coding is assuming that the walrcv_command()
subroutine cannot throw an error, which I would consider dangerous
even if it were a fixed subroutine. If it's a hook that's doing
unknown stuff, that seems a completely untenable assumption. You
really need either to hook the cleanup action into normal error
recovery, or to use a PG_TRY block.
regards, tom lane
--
Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-committers
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: pgsql: Fix connection leak in DROP SUBSCRIPTION command.
@ 2017-02-21 21:57 Michael Paquier <michael.paquier@gmail.com>
parent: Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 8+ messages in thread
From: Michael Paquier @ 2017-02-21 21:57 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Fujii Masao <fujii@postgresql.org>; pgsql-committers
On Wed, Feb 22, 2017 at 4:12 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> Fujii Masao <fujii@postgresql.org> writes:
>> Fix connection leak in DROP SUBSCRIPTION command.
>> Previously the command forgot to close the connection to the publisher
>> when it failed to drop the replication slot.
>
> If there's a bug here, this seems like an extremely unreliable way of
> fixing it. What if an error gets thrown before you reach that ereport?
>
> In other words, this coding is assuming that the walrcv_command()
> subroutine cannot throw an error, which I would consider dangerous
> even if it were a fixed subroutine. If it's a hook that's doing
> unknown stuff, that seems a completely untenable assumption. You
> really need either to hook the cleanup action into normal error
> recovery, or to use a PG_TRY block.
To be honest, I have thought about using PG_ENSURE_ERROR_CLEANUP()
when seeing the thread. If other ERROR messages are generated in the
future that the current fix would be unreliable.
--
Michael
--
Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-committers
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: pgsql: Fix connection leak in DROP SUBSCRIPTION command.
@ 2017-02-21 23:39 Fujii Masao <masao.fujii@gmail.com>
parent: Michael Paquier <michael.paquier@gmail.com>
0 siblings, 2 replies; 8+ messages in thread
From: Fujii Masao @ 2017-02-21 23:39 UTC (permalink / raw)
To: Michael Paquier <michael.paquier@gmail.com>; +Cc: Tom Lane <tgl@sss.pgh.pa.us>; Fujii Masao <fujii@postgresql.org>; pgsql-committers
On Wed, Feb 22, 2017 at 6:57 AM, Michael Paquier
<michael.paquier@gmail.com> wrote:
> On Wed, Feb 22, 2017 at 4:12 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> Fujii Masao <fujii@postgresql.org> writes:
>>> Fix connection leak in DROP SUBSCRIPTION command.
>>> Previously the command forgot to close the connection to the publisher
>>> when it failed to drop the replication slot.
>>
>> If there's a bug here, this seems like an extremely unreliable way of
>> fixing it. What if an error gets thrown before you reach that ereport?
>>
>> In other words, this coding is assuming that the walrcv_command()
>> subroutine cannot throw an error,
Yes, but I agree that walrcv_command() may be changed in the future so that
an error is thrown and current coding is not reliable in that case.
>> which I would consider dangerous
>> even if it were a fixed subroutine. If it's a hook that's doing
>> unknown stuff, that seems a completely untenable assumption. You
>> really need either to hook the cleanup action into normal error
>> recovery, or to use a PG_TRY block.
>
> To be honest, I have thought about using PG_ENSURE_ERROR_CLEANUP()
> when seeing the thread. If other ERROR messages are generated in the
> future that the current fix would be unreliable.
What about the attached patch?
Regards,
--
Fujii Masao
--
Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-committers
Attachments:
bugfix.patch (application/octet-stream, 1.3K) download
*** a/src/backend/commands/subscriptioncmds.c
--- b/src/backend/commands/subscriptioncmds.c
***************
*** 545,563 **** DropSubscription(DropSubscriptionStmt *stmt)
"drop the replication slot \"%s\"", slotname),
errdetail("The error was: %s", err)));
! if (!walrcv_command(wrconn, cmd.data, &err))
{
/* Close the connection in case of failure */
walrcv_disconnect(wrconn);
! ereport(ERROR,
! (errmsg("could not drop the replication slot \"%s\" on publisher",
! slotname),
! errdetail("The error was: %s", err)));
}
! else
! ereport(NOTICE,
! (errmsg("dropped replication slot \"%s\" on publisher",
! slotname)));
walrcv_disconnect(wrconn);
--- 545,569 ----
"drop the replication slot \"%s\"", slotname),
errdetail("The error was: %s", err)));
! PG_TRY();
! {
! if (!walrcv_command(wrconn, cmd.data, &err))
! ereport(ERROR,
! (errmsg("could not drop the replication slot \"%s\" on publisher",
! slotname),
! errdetail("The error was: %s", err)));
! else
! ereport(NOTICE,
! (errmsg("dropped replication slot \"%s\" on publisher",
! slotname)));
! }
! PG_CATCH();
{
/* Close the connection in case of failure */
walrcv_disconnect(wrconn);
! PG_RE_THROW();
}
! PG_END_TRY();
walrcv_disconnect(wrconn);
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: pgsql: Fix connection leak in DROP SUBSCRIPTION command.
@ 2017-02-22 02:14 Petr Jelinek <petr.jelinek@2ndquadrant.com>
parent: Fujii Masao <masao.fujii@gmail.com>
1 sibling, 0 replies; 8+ messages in thread
From: Petr Jelinek @ 2017-02-22 02:14 UTC (permalink / raw)
To: Fujii Masao <masao.fujii@gmail.com>; Michael Paquier <michael.paquier@gmail.com>; +Cc: Tom Lane <tgl@sss.pgh.pa.us>; Fujii Masao <fujii@postgresql.org>; pgsql-committers
On 22/02/17 00:39, Fujii Masao wrote:
> On Wed, Feb 22, 2017 at 6:57 AM, Michael Paquier
> <michael.paquier@gmail.com> wrote:
>> On Wed, Feb 22, 2017 at 4:12 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>>> Fujii Masao <fujii@postgresql.org> writes:
>>>> Fix connection leak in DROP SUBSCRIPTION command.
>>>> Previously the command forgot to close the connection to the publisher
>>>> when it failed to drop the replication slot.
>>>
>>> If there's a bug here, this seems like an extremely unreliable way of
>>> fixing it. What if an error gets thrown before you reach that ereport?
>>>
>>> In other words, this coding is assuming that the walrcv_command()
>>> subroutine cannot throw an error,
>
> Yes, but I agree that walrcv_command() may be changed in the future so that
> an error is thrown and current coding is not reliable in that case.
>
>>> which I would consider dangerous
>>> even if it were a fixed subroutine. If it's a hook that's doing
>>> unknown stuff, that seems a completely untenable assumption. You
>>> really need either to hook the cleanup action into normal error
>>> recovery, or to use a PG_TRY block.
>>
>> To be honest, I have thought about using PG_ENSURE_ERROR_CLEANUP()
>> when seeing the thread. If other ERROR messages are generated in the
>> future that the current fix would be unreliable.
>
> What about the attached patch?
>
Looks more or less like what we do in CREATE SUBSCRIPTION for this, so I
guess it's okay.
--
Petr Jelinek http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services
--
Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-committers
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: pgsql: Fix connection leak in DROP SUBSCRIPTION command.
@ 2017-02-22 04:27 Michael Paquier <michael.paquier@gmail.com>
parent: Fujii Masao <masao.fujii@gmail.com>
1 sibling, 1 reply; 8+ messages in thread
From: Michael Paquier @ 2017-02-22 04:27 UTC (permalink / raw)
To: Fujii Masao <masao.fujii@gmail.com>; +Cc: Tom Lane <tgl@sss.pgh.pa.us>; Fujii Masao <fujii@postgresql.org>; pgsql-committers
On Wed, Feb 22, 2017 at 8:39 AM, Fujii Masao <masao.fujii@gmail.com> wrote:
> On Wed, Feb 22, 2017 at 6:57 AM, Michael Paquier
> <michael.paquier@gmail.com> wrote:
>> On Wed, Feb 22, 2017 at 4:12 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>>> Fujii Masao <fujii@postgresql.org> writes:
>>>> Fix connection leak in DROP SUBSCRIPTION command.
>>>> Previously the command forgot to close the connection to the publisher
>>>> when it failed to drop the replication slot.
>>>
>>> If there's a bug here, this seems like an extremely unreliable way of
>>> fixing it. What if an error gets thrown before you reach that ereport?
>>>
>>> In other words, this coding is assuming that the walrcv_command()
>>> subroutine cannot throw an error,
>
> Yes, but I agree that walrcv_command() may be changed in the future so that
> an error is thrown and current coding is not reliable in that case.
>
>>> which I would consider dangerous
>>> even if it were a fixed subroutine. If it's a hook that's doing
>>> unknown stuff, that seems a completely untenable assumption. You
>>> really need either to hook the cleanup action into normal error
>>> recovery, or to use a PG_TRY block.
>>
>> To be honest, I have thought about using PG_ENSURE_ERROR_CLEANUP()
>> when seeing the thread. If other ERROR messages are generated in the
>> future that the current fix would be unreliable.
>
> What about the attached patch?
Thanks for the patch. That looks good to me.
--
Michael
--
Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-committers
^ permalink raw reply [nested|flat] 8+ messages in thread
* pgsql: Fix connection leak in DROP SUBSCRIPTION command, take 2.
@ 2017-03-08 14:45 Fujii Masao <fujii@postgresql.org>
0 siblings, 0 replies; 8+ messages in thread
From: Fujii Masao @ 2017-03-08 14:45 UTC (permalink / raw)
To: pgsql-committers
Fix connection leak in DROP SUBSCRIPTION command, take 2.
Commit 898a792eb8283e31efc0b6fcbc03bbcd5f7df667 fixed the connection
leak issue, but it was an unreliable way of bugfix. This bugfix was
assuming that walrcv_command() subroutine cannot throw an error,
but it's untenable assumption. For example, if it will be changed
so that an error is thrown, connection leak issue will happen again.
This patch ensures that the connection is closed even when
walrcv_command() subroutine throws an error.
Patch by me, reviewed by Petr Jelinek and Michael Paquier
Discussion: https://www.postgresql.org/message-id/2058.1487704345@sss.pgh.pa.us
Branch
------
master
Details
-------
http://git.postgresql.org/pg/commitdiff/77d21970ae19418f321e6a76ddf1a57ae999c77a
Modified Files
--------------
src/backend/commands/subscriptioncmds.c | 24 +++++++++++++++---------
1 file changed, 15 insertions(+), 9 deletions(-)
--
Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-committers
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: pgsql: Fix connection leak in DROP SUBSCRIPTION command.
@ 2017-03-08 14:46 Fujii Masao <masao.fujii@gmail.com>
parent: Michael Paquier <michael.paquier@gmail.com>
0 siblings, 0 replies; 8+ messages in thread
From: Fujii Masao @ 2017-03-08 14:46 UTC (permalink / raw)
To: Michael Paquier <michael.paquier@gmail.com>; +Cc: Tom Lane <tgl@sss.pgh.pa.us>; Fujii Masao <fujii@postgresql.org>; pgsql-committers
On Wed, Feb 22, 2017 at 1:27 PM, Michael Paquier
<michael.paquier@gmail.com> wrote:
> On Wed, Feb 22, 2017 at 8:39 AM, Fujii Masao <masao.fujii@gmail.com> wrote:
>> On Wed, Feb 22, 2017 at 6:57 AM, Michael Paquier
>> <michael.paquier@gmail.com> wrote:
>>> On Wed, Feb 22, 2017 at 4:12 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>>>> Fujii Masao <fujii@postgresql.org> writes:
>>>>> Fix connection leak in DROP SUBSCRIPTION command.
>>>>> Previously the command forgot to close the connection to the publisher
>>>>> when it failed to drop the replication slot.
>>>>
>>>> If there's a bug here, this seems like an extremely unreliable way of
>>>> fixing it. What if an error gets thrown before you reach that ereport?
>>>>
>>>> In other words, this coding is assuming that the walrcv_command()
>>>> subroutine cannot throw an error,
>>
>> Yes, but I agree that walrcv_command() may be changed in the future so that
>> an error is thrown and current coding is not reliable in that case.
>>
>>>> which I would consider dangerous
>>>> even if it were a fixed subroutine. If it's a hook that's doing
>>>> unknown stuff, that seems a completely untenable assumption. You
>>>> really need either to hook the cleanup action into normal error
>>>> recovery, or to use a PG_TRY block.
>>>
>>> To be honest, I have thought about using PG_ENSURE_ERROR_CLEANUP()
>>> when seeing the thread. If other ERROR messages are generated in the
>>> future that the current fix would be unreliable.
>>
>> What about the attached patch?
>
> Thanks for the patch. That looks good to me.
Petr and Michael,
Thanks for the review! Pushed.
Regards,
--
Fujii Masao
--
Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-committers
^ permalink raw reply [nested|flat] 8+ messages in thread
end of thread, other threads:[~2017-03-08 14:46 UTC | newest]
Thread overview: 8+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2017-02-21 18:36 pgsql: Fix connection leak in DROP SUBSCRIPTION command. Fujii Masao <fujii@postgresql.org>
2017-02-21 19:12 ` Tom Lane <tgl@sss.pgh.pa.us>
2017-02-21 21:57 ` Michael Paquier <michael.paquier@gmail.com>
2017-02-21 23:39 ` Fujii Masao <masao.fujii@gmail.com>
2017-02-22 02:14 ` Petr Jelinek <petr.jelinek@2ndquadrant.com>
2017-02-22 04:27 ` Michael Paquier <michael.paquier@gmail.com>
2017-03-08 14:46 ` Fujii Masao <masao.fujii@gmail.com>
2017-03-08 14:45 pgsql: Fix connection leak in DROP SUBSCRIPTION command, take 2. Fujii Masao <fujii@postgresql.org>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox