public inbox for pgsql-hackers@postgresql.org  
help / color / mirror / Atom feed
From: Fujii Masao <masao.fujii@gmail.com>
To: Rafia Sabih <rafia.pghackers@gmail.com>
Cc: Chao Li <li.evan.chao@gmail.com>
Cc: vignesh C <vignesh21@gmail.com>
Cc: PostgreSQL-development <pgsql-hackers@postgresql.org>
Subject: Re: Set notice receiver before libpq connection startup
Date: Fri, 22 May 2026 22:42:00 +0900
Message-ID: <CAHGQGwHU2E7h7XBCBNK7OJ+OAx7Xkwn+yUb7o5p5GxExi4fzAw@mail.gmail.com> (raw)
In-Reply-To: <CA+FpmFdfyBhuiou1uqe94UR3WCg57wM5FsooUx2w27aABGoyag@mail.gmail.com>
References: <A2B8B7DE-C119-492F-A9FA-14CF86849777@gmail.com>
	<CAHGQGwHnz7FoSx+qQsAHBx_j8Tks+SC-kAPTevrKYfrL08Ee9Q@mail.gmail.com>
	<978D8971-08C3-4AAD-AE8B-976D753C882A@gmail.com>
	<CALDaNm3UyoQ91gW2bRP4PXnnfAv3GfmCik614-AtQCiEUAjQYw@mail.gmail.com>
	<6B9A85F9-B632-4286-98AF-9EC435019055@gmail.com>
	<CA+FpmFdfyBhuiou1uqe94UR3WCg57wM5FsooUx2w27aABGoyag@mail.gmail.com>

On Fri, May 22, 2026 at 8:33 PM Rafia Sabih <rafia.pghackers@gmail.com> wrote:
> Here are my two cents,
> we need not to check conn is null here
> + conn = libpqsrv_connect_start(connstr);
> + if (conn != NULL)
> + PQsetNoticeReceiver(conn, libpqsrv_notice_receiver,
> + "received message via remote connection");
> because it is done so in  PQsetNoticeReceiver anyway. Also, since there is no else here so it doesn't make sense more, because if it is null then also we will just continue with the next function call.

Yes, but I'm fine with the current code in the patch. That code makes
the intent explicit, i.e., install the notice receiver only when a connection
object actually exists. That said, I'm also OK with simply calling
PQsetNoticeReceiver() without that check.


> Another point is, in pg_connect_server I don't get the value of adding another PGConn variable start_conn, can't we use conn itself...?
> I hope this helps.

Not only connect_pg_server() but libpqsrv_connect_complete() has
a PG_TRY/PG_CATCH block. So if start_conn were not used, an error thrown
in libpqsrv_connect_complete() could cause the current connection (conn) to
be cleaned up twice unexpectedly: once in libpqsrv_connect_complete() and
again in connect_pg_server(). I guess that's why Chao introduced start_conn.

Regards,

-- 
Fujii Masao






reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-hackers@postgresql.org
  Cc: masao.fujii@gmail.com, rafia.pghackers@gmail.com, li.evan.chao@gmail.com, vignesh21@gmail.com
  Subject: Re: Set notice receiver before libpq connection startup
  In-Reply-To: <CAHGQGwHU2E7h7XBCBNK7OJ+OAx7Xkwn+yUb7o5p5GxExi4fzAw@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox