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 1x0zIm-004vBH-0n for pgsql-hackers@arkaria.postgresql.org; Mon, 31 Aug 2026 10:31:44 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1x0zIi-00H2bK-2a for pgsql-hackers@arkaria.postgresql.org; Mon, 31 Aug 2026 10:31:40 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1x0zIi-00H2bB-1P for pgsql-hackers@lists.postgresql.org; Mon, 31 Aug 2026 10:31:40 +0000 Received: from mail-wm1-x330.google.com ([2a00:1450:4864:20::330]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1x0zIf-00000002ArX-2haN for pgsql-hackers@postgresql.org; Mon, 31 Aug 2026 10:31:39 +0000 Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-4995b0343c1so33050685e9.3 for ; Mon, 31 Aug 2026 03:31:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec.at; s=google; t=1788172296; x=1788777096; darn=postgresql.org; h=message-id:date:content-transfer-encoding:content-type:mime-version :comments:references:in-reply-to:subject:cc:to:from:from:to:cc :subject:date:message-id:reply-to:content-type; bh=0OhGi9vhr7pW4Pt6nc0IzCuQ0VNjevoy3HSOfjKhcCE=; b=hk7NzX/TSP/UTmG78krJE/eIvGcYexA4LrWJ7CSPLkb6DUpvB9icosWNdUZeXOYGHR bCccFLDjOmjWhA2U5W7vZpyp8lzmFQTOxccvO8rSHpUt0QNHOdiljVkL9SSbXOxXw6PZ dQMO4rUEGW05AesnvCYbaNMrBczHO1+Dl8nfS0c6/D6tnDhNpcyCylZmV73/OiZmmbEB LOJ1fN85al2F09HIH5fQ0PTGso8eA+ycH86/eGGgwIdZ3MqQPjYXyY+rfpSlMS0SWnhG HM3tpaHwM0AfRoTKJdn0qbSuEMCJwkugFaGPu8TdWirhsyibGgFcSZwYPrMDfl05mHat HeqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788172296; x=1788777096; h=message-id:date:content-transfer-encoding:content-type:mime-version :comments:references:in-reply-to:subject:cc:to:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=0OhGi9vhr7pW4Pt6nc0IzCuQ0VNjevoy3HSOfjKhcCE=; b=Bq7VkmPOY+SEQFpYtaw4IC0K8ZPrhUOurAuzq/vSDli3dqg8tVc0wb/XzJjH8w9VWq zz/dOJWrToAddLPe518XbedI1kCijzRmhWv9gTIqeoW0uDjdhVtTSlCt/wJJ+R3KEPD6 sxYEurzd/H9rCa+JPJE8qmr2R1hmTf80eXXAAXxJCCd4SIZ0gJ6Ns31f0Huzkf/iaYA+ ubGvHQU48Dkg2O+xtLMjEW+0lL3H9NHDovd9AaUOFy4dytPSHa4pz7iqNw05vENKOWmY iUux+Nl6GRN4tcZF8f79AW4/d8OZ3VSl2tZid3Otq/UN0uhcKibw+84H6OpWZdOaEQRb foxw== X-Forwarded-Encrypted: i=1; AHgh+RoHsNY850whUG6nP1tRxblmu3WwLURN89Uapvooc0nqIuIJXqo01FmjAipl4H4sn4G1ysW0VLJ8N4GF57jC@postgresql.org X-Gm-Message-State: AFuF++lUIteG4wZg8/YBMGZNB8AQS7G7BIbrQv545HY9Xjrt21VlUJdS 7G7fmH5tjIZPGzQ9dhqQX8tZygll//j5pDSvaORs5+wuRowXTHtg3LjzSQaWS9dspbM= X-Gm-Gg: AR+sD10kQthlU9FCDJXS7qdHTambIeHMZOv7r3eTGUSE2czH77vyWAhGlXtuVUZNr5X LGYAf/MLJfb5ASvompaKeeOa3/SnImeNMjn5kxj2SueRP5Z2jQMpUKbbULxfzYhwmVJD3lXPg48 D9I/vJXoD3GspMOwgdlxa1xipEartCIA3xhEnFkVgLTdHmP57J2R/FFc4RRe84y4pc2L88ANHcI O47LFrzRBDurVq9MopIeQerT1+9U+AEgiV+HqA8fFgHGtfjQ3kDy/Ju86o3hodRdvpQs7wLLqPT ODOgndLRLQxcqW+ItDnGnWyD6fj/ruJd2HgA92HYlyY9WR2FXL4QE93Ue6jq6sqAeBlCRABiS2x x2JvNjcvogmyIYTbvl1j7iCDQJqn+l36oAFwPiB0UxxToaQP7NZjYZQn43v+tC6zQARx1o6GNdm 3+H3hzE3cy2/NiE87QHfWX3FukovDdJ2Jatz8RmvRmM3aYL4H5GxZKiA5J7fOcn9Me/OSlNdWU6 xIoYGw3//Ke X-Received: by 2002:a05:600c:1f8d:b0:499:621a:2ec2 with SMTP id 5b1f17b1804b1-49b91c17c41mr354153105e9.3.1788172296482; Mon, 31 Aug 2026 03:31:36 -0700 (PDT) Received: from localhost (109-81-170-190.rct.o2.cz. [109.81.170.190]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-49b955e7906sm232046825e9.1.2026.08.31.03.31.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Aug 2026 03:31:36 -0700 (PDT) From: Antonin Houska To: Bharath Rupireddy cc: Nathan Bossart , PostgreSQL-development , alvherre@kurilemu.de Subject: Re: REPACK (CONCURRENTLY) backend waits indefinitely when decoding worker fails to start In-reply-to: References: Comments: In-reply-to Bharath Rupireddy message dated "Fri, 28 Aug 2026 13:20:00 -0700." X-Mailer: MH-E 8.6+git; nmh 1.8; GNU Emacs 28.3 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Mon, 31 Aug 2026 12:31:35 +0200 Message-ID: <27780.1788172295@localhost> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Bharath Rupireddy wrote: > On Thu, Aug 27, 2026 at 9:47=E2=80=AFAM Nathan Bossart wrote: > > > > On Thu, Aug 27, 2026 at 09:41:49AM -0700, Bharath Rupireddy wrote: > > > REPACK (CONCURRENTLY) starts a decoding bgworker and then waits in > > > start_repack_decoding_worker() for the worker to set a shared-memory > > > flag. The wait has no liveness check on the worker itself. If the > > > worker never reaches that point (e.g., fork failure under memory > > > pressure, or when BecomeLockGroupMember() returns false, or early exit > > > before the shm_mq error redirect is set up), the backend waits > > > indefinitely with no way out other than cancellation. I reproduced > > > this with an induced fork failure, so I think we need to tighten this > > > for both PG19 and HEAD branches. > > > > Oops, I just concurrently reported this [0]. Note that teardown can > > deadlock, too. > > > > [0] https://postgr.es/m/apBpOVZOyqrakEr_%40nathan >=20 > Thanks. Here's my first attempt at fixing both the fork failure hang > and the teardown deadlock. I tried to use the parallel query approach > as much as possible. >=20 > The fork failure hang can occur because the backend running concurrent > repack sleeps on a CV and ignores the SIGUSR1 sent via bgw_notify_pid > by the postmaster upon fork failure. >=20 > The teardown deadlock can occur because the backend waits for the > worker to exit before detaching the error queue, while the worker is > blocked writing to a full queue, so both end up waiting on each other. >=20 > Although these issues seem rare to hit, I think it's good to tighten > the repack code because users can see them via SQL. Therefore, I think > we need to backpatch these to PG19. Please have a look at the attached > patch. Thanks for the fix(es). One thing I'm not sure I understand is: @@ -3851,9 +3900,11 @@ ProcessRepackMessages(void) =20 /* * Nothing to do if we haven't launched the worker yet or have already - * terminated it. + * terminated it. stop_repack_decoding_worker() detaches the error queue + * before clearing decoding_worker, so also bail out once error_mqh is + * gone. */ - if (decoding_worker =3D=3D NULL) + if (decoding_worker =3D=3D NULL || decoding_worker->error_mqh =3D=3D NULL) return; =20 /* I don't think that stop_repack_decoding_worker() can clear ->error_mqh w/o also clearing decoding_worker. Other than that, I'm not sure you need to mention the condition variable in the comments. And maybe even the mentions of parallel workers are not necessary. > While here, I noticed that the same wait event is used for both the > worker startup wait and the file export wait. Ideally these would have > separate wait events, but given that the startup wait is typically > very short, reusing the same one seems fine. I think that initially I also considered this situation not worth a new wait event, but I probably had missed an existing one: WAIT_EVENT_BGWORKER_STARTUP. It's already used for multiple workers, so we could perhaps use it here. --=20 Antonin Houska Web: https://www.cybertec-postgresql.com