Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wB5Aj-000ib8-10 for pgsql-hackers@arkaria.postgresql.org; Fri, 10 Apr 2026 06:16:53 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wB5Ah-009iEY-1b for pgsql-hackers@arkaria.postgresql.org; Fri, 10 Apr 2026 06:16:52 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wB5Ah-009iEQ-0h for pgsql-hackers@lists.postgresql.org; Fri, 10 Apr 2026 06:16:52 +0000 Received: from mail-oo1-xc2b.google.com ([2607:f8b0:4864:20::c2b]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wB5Ag-00000000Hhl-0NIR for pgsql-hackers@postgresql.org; Fri, 10 Apr 2026 06:16:51 +0000 Received: by mail-oo1-xc2b.google.com with SMTP id 006d021491bc7-68a253b7301so954117eaf.1 for ; Thu, 09 Apr 2026 23:16:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1775801810; cv=none; d=google.com; s=arc-20240605; b=lw7sdAoMCQ5RIFWyuLPnos224BAsZJXuiJ8lW4j64G0OVJLQh1kG42XnRJhT7KiLcI YUUhYYX4RrcoQKo27amVG3ZV2DFJ/zTKsUrezT6j1l8Swgf0q7iOd/LHSQSKTMiikH7/ 7clAHyKBmp5cd0/2HujszhHB6OmKEh08OaAQYNQq/xdk6pCGNz+fP8xl8Odo9II80/qi Rjo7ZtOtvAq+I91HNhcz1i/En7R8QXC32fg4zm2agQGWuoUCFKRtvq10qctBuJMCvspa ZNncaPTDr0gsD55PTHy/06TaETm0sWNdacak7ABBkdVd8AAhfuNxNKc8PzPcQmvjzCLa 1uZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=/NsCiZPiVX2fKvk99UQeVjEDH/fkr+hYoxJ4qtiyoRA=; fh=BqCsLkuGKCcTArCRHu+S+NvQEVNhw5ffdUdV1K/2bjY=; b=MACZkCykxNex8G/a3inItBsUcZb9QKt8eXAvASR6mAOm0pU/dOLBv7T6wYLAjguTzB 1XT8dZg1l2VPLWWhz0CnEq5c92IscL++ZcOoDo/3iEDDuD4wHRtXaE1VvNlab0Jc6cOq I6qLfOwhRPj//p/BCJWYio/8p/tmS1I+fiBpzv10QlMmRE6GiVrWmXX5ToPe/wRO+697 DMq/l2jhOsUpMJTKICVkAzjuKb1v2kjFEtm2Bq1TysBlKWovSWFT7JN6ZvclalloHJx+ j4gQ03Xf3tVXiwFaP+yhB1Zv/V5QB+eVoNkkEQm/Bh1fq04gilcMOV9Wd6bzuxIkil6O D3Mg==; darn=postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1775801810; x=1776406610; darn=postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=/NsCiZPiVX2fKvk99UQeVjEDH/fkr+hYoxJ4qtiyoRA=; b=VEbm8ilxFvz+AeewCr8edS1dDJaiQ0HDz1fYdPvJbFJl/wuAV8on69QFh4pnKcutrT G+R3JMICoCgDl+vijNmg85Pl1Akfev/WWH7FuktXKQm92GMZvxpiFs3fJaLSDlNFHLGT 84lQfXIyz7ImEN5JIqrUvH3/JBFXOew/4MGVc1gevsGr4508LExLqTwbUqUr+rEEDTqC sQ6I6YTEn1jpwZ+dW6XvFu+ZC2iZoOVR4VT7BufQz/j3B9g/Q1IYDUNJTyFwXyf5IiZt rA3P/Z4TLMLK/DmH1E5N+tEhMjZmaFpGDWl/LNlFcap/bjHqp2uWMBFtb+klv8IrHoVD vKjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775801810; x=1776406610; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=/NsCiZPiVX2fKvk99UQeVjEDH/fkr+hYoxJ4qtiyoRA=; b=e7HIasBUEdiIW34XRaBWqgQbZBowW6vV3AufP5f0eE9fSsLsRltDcy9G8dZYS1BPR6 lW/2A9nZCP/+NcMMFE9yMqoEpHrKMoZxQhyjA7R0/d7E/vz1uE2sgVLoTszLARa9/kN6 jZw5OaGdS5ZkoiqH0Mhw2nvydCRCF/f+u0ji+xq0SaAk1oyrmFomkblmehg6W3LewEnh olC97F7KP2afzHlZx7Rdn6h7RbAxHpQzbFBaiszaPXJfGBjyPheGkcsge3oX1if/Scp0 gqVwVCYKV9xsWpuWGPhdh22P8OR1D3hS/DHdxF9ZGjDtQpARIGa0M3yfW9iiwK2attxd jQBA== X-Forwarded-Encrypted: i=1; AJvYcCVqpppXi0kMIidS52p3EsXZHH8GpXTwvJnRuEB5ENXZ7f7iAhFn8NXT/ittNhkTIc9Na1zYrcrsHNPkYQxO@postgresql.org X-Gm-Message-State: AOJu0YwBl7mrjmjSB2d35UBx9IJGMLSaTrLf2fA7UAf47sTH6JSNda/X pz1wYDRnzwAFy1u3eSRMwF8IESGDdyoNvjEYhUGktxkqI4cIF6yxZVT91Ww11A035PsuSa6Cj0n Ln6Ea8iY4gpxhl3mPbyK5Wmz30N7l8VA= X-Gm-Gg: AeBDiet3EsQl/K1ZdQjmDD5YesbyJVRroJ3YiIRwPkuQ+byaIlW4nqX08w0ia3x7MAG 9C92moSQtFEx/Xdt3+mg9kDUVFGStx8YU304TdIWjz/nSI9d4LRFFZMWEk60tyVVqK4Z9pE48a9 CMgKoPnVfgw5BVR/dr54JyyfAUqW92mPA1wWuNNF5EUVAIHUViGBg9UpbsrzLDK+E/VGYuN7o4v 4nx9k5kl9nDgC6ty+ECDjW3GXMexBiE3z7xxD/8UMvGr8B3vkMLNACFl5A4OtYinQRvwISsnisA zV7mDsQsHJaiir+N+UqQwth6qlKn47qGWtsS7MF9Zw== X-Received: by 2002:a05:6820:201b:b0:67e:160c:36c3 with SMTP id 006d021491bc7-68be85d40d5mr1031949eaf.48.1775801809837; Thu, 09 Apr 2026 23:16:49 -0700 (PDT) MIME-Version: 1.0 References: <74381238-4E8A-4621-B794-57025DCCE0BA@gmail.com> <6a42c40e-eb81-4212-9bca-8c0eb02d47d1@proxel.se> In-Reply-To: From: Fujii Masao Date: Fri, 10 Apr 2026 15:16:37 +0900 X-Gm-Features: AQROBzDo3thRHnlR90L3evgovcYXnxMDB9fKrC8Ozvy4FWBO18adAbBfogxI7_A Message-ID: Subject: Re: Use proc_exit() in WalRcvWaitForStartPosition To: Xuneng Zhou Cc: Andreas Karlsson , Chao Li , PostgreSQL-development Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Thu, Apr 9, 2026 at 10:09=E2=80=AFAM Xuneng Zhou = wrote: > > On Thu, Apr 9, 2026 at 5:00=E2=80=AFAM Andreas Karlsson wrote: > > > > On 4/8/26 11:08 AM, Chao Li wrote: > > > While working on another patch, I happened to notice that WalRcvWaitF= orStartPosition() calls raw exit(1). I think this should use proc_exit(1) i= nstead, so that the normal cleanup machinery is not bypassed. > > > > > > This tiny patch just replaces exit(1) with proc_exit(1) in WalRcvWait= ForStartPosition(). > > > > This looks likely to be correct since when we exit in WalReceiverMain() > > (on WALRCV_STOPPING and WALRCV_STOPPED) we call proc_exit(1). I feel we > > should exit the same way in WalRcvWaitForStartPosition() as we do in > > WalReceiverMain() and if not I would like a comment explaining why thos= e > > two cases are different. > > +1 +1 > WalRcvWaitForStartPosition, WALRCV_STOPPING before entering wait loop > uses proc_exit(0) for WALRCV_STOPPING, while this path should probably > use proc_exit(0) as well (not proc_exit(1)), since the stop was a > requested shutdown, not an error. Using exit code 1 for a clean > stop-on-request seems inconsistent. The requested shutdown is handled in ShutdownWalRcv(), which sets the state= to WALRCV_STOPPING and sends SIGTERM to the walreceiver. Although this might be considered a normal shutdown (suggesting exit code 0= ), when the walreceiver receives SIGTERM it exits via ereport(FATAL), resultin= g in exit code 1. In contrast, if it exits early in WalRcvWaitForStartPositio= n() due to the WALRCV_STOPPING state, it uses exit code 0, as you noted. So there seems to be some inconsistency in exit codes. That said, the exit code (0 vs 1) does not affect behavior, since the postmaster treats both as non-crash exits. For consistency, I would prefer using exit code 1 in proc_exit() in WalRcvWaitForStartPosition(), to match the ereport(FATAL) path. But I'm fin= e with other approaches as well. Also, the comment at the top of walreceiver.c may need updating: * Normal termination is by SIGTERM, which instructs the walreceiver to * exit(0). Emergency termination is by SIGQUIT; like any postmaster child * process, the walreceiver will simply abort and exit on SIGQUIT. A close * of the connection and a FATAL error are treated not as a crash but as * normal operation. Regards, --=20 Fujii Masao