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.94.2) (envelope-from ) id 1tq3B1-00GCY1-3a for pgsql-hackers@arkaria.postgresql.org; Thu, 06 Mar 2025 04:49:43 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1tq3Az-00FdPt-Dj for pgsql-hackers@arkaria.postgresql.org; Thu, 06 Mar 2025 04:49:41 +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.94.2) (envelope-from ) id 1tq3Ay-00FdPl-RP for pgsql-hackers@lists.postgresql.org; Thu, 06 Mar 2025 04:49:41 +0000 Received: from mail-pj1-x102d.google.com ([2607:f8b0:4864:20::102d]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1tq3Au-001EZb-1e for pgsql-hackers@postgresql.org; Thu, 06 Mar 2025 04:49:40 +0000 Received: by mail-pj1-x102d.google.com with SMTP id 98e67ed59e1d1-2ff6ae7667dso231685a91.0 for ; Wed, 05 Mar 2025 20:49:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=leadboat.com; s=google; t=1741236576; x=1741841376; darn=postgresql.org; h=user-agent:in-reply-to:content-disposition:mime-version:references :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=YgspxwhUEcYZC3zdbgfAY5oFaseVu6H5QYvzBWSB/mk=; b=dyUZaoGT764+nVqossPuovmmhxBbLdJK0Cb1KQRutaCctjQDv9bsfR6xR9nuZQ4Stg DRacNBElFs6bfPDXdkrkB0Po9xI7lHtm2qjnwuKlNv7Q+Wuvvp52qZ0YjMmrIPWT9L/n EIgCRZoRsJSqtB9uLMGWFxiQhBq918TL1mrfY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741236576; x=1741841376; h=user-agent:in-reply-to:content-disposition:mime-version:references :message-id:subject:cc:to:from:date:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YgspxwhUEcYZC3zdbgfAY5oFaseVu6H5QYvzBWSB/mk=; b=IARSM+sOGCvwIp0PeGhAiBlgC3hvSyg7WNb7UM00fQ3/W82o6wMvXVtiTyjBMj0wIE j+O5I2uns8aeJsr9VaOvc24uv4c9jpiNIEgtkc1dYL0ApfsYy2P5D+sTazJ8ib+EG3ln Hlu8BMZ+HSkWy6XJadvqjPX0L8vxS+vwX8uuv5I64iDkbxqVINnScKyWU7NeZXWEdV8f RwEZSc7Dbp1lfNMS4FjyIVmfcLvuxPXsTqlvcsQWPArCjX7ho9sDV31JbCCnQUSk4jzV CZxwUAZLZWqckYAhjOtBXkSoooVz3w13WasJKQNkjwTBCwvEtvxM5PPuD4CBCYjzbhJt CQ4w== X-Forwarded-Encrypted: i=1; AJvYcCX8CpCP/ya0LoUGK5QMr68e5RueHy5cdLtZz75iJIbBBPeOpN1TgBa1yZAoeLp3V+AWnVxamvuCOPGL6gJ7@postgresql.org X-Gm-Message-State: AOJu0YxQRhXI8w68Q582NSxGyUGGhoIzYZjbGPjUbDofnhfScMIvSdPp 1+5uFuYMGmkeH0zbAOaYfa0I7DjKC3yIwZRzpc6QZi83cNeCTR3wTE7hBOjsPg== X-Gm-Gg: ASbGnct4Ur4iddxq3gYYKqmyKsGOXCICvlMRm53ClLQf2zyN00LPzK5pa7dqUb0Ki2R feG5cprNDMkqeZ7swPLMCaH4WVjAFLCUIcRrwESRyOYY2pXH5c9AQs01hr7E6Vg50PPpN1GNlPZ 1n8uvh56XI9K/7QKOFi0a6ZAhJnJ+/NQsl0NJG8ceBS14dBKRa1iD7auGxHu71zmCCHuKkxE9Gl tL+ymkhXfV/FM5VdGcj6ygfgFn2uevBZHwOfrco2Qt9K6ACm/YmWGhZ2Da5Y8wCA7bBNjvgdNIK CnMepsXi5jshd9ICy4Fs9Dp3TYhlsBrhN24RSrs= X-Google-Smtp-Source: AGHT+IFpOAu43ZcUHHbS4LImDekZjy/IlBTeyBzilNUjC02ukn5sIWHhPxsC9aFxY/rCuYCtgP16KA== X-Received: by 2002:a05:6a20:394b:b0:1ee:6d23:20ab with SMTP id adf61e73a8af0-1f3494775c4mr11049134637.10.1741236575806; Wed, 05 Mar 2025 20:49:35 -0800 (PST) Received: from google.com ([2600:1702:a20:5750::46]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7369853818esm325112b3a.168.2025.03.05.20.49.34 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 05 Mar 2025 20:49:35 -0800 (PST) Date: Wed, 5 Mar 2025 20:49:33 -0800 From: Noah Misch To: Andres Freund Cc: Tomas Vondra , Heikki Linnakangas , Thomas Munro , "pgsql-hackers@postgresql.org" Subject: Re: Refactoring postmaster's code to cleanup after child exit Message-ID: <20250306044933.7a.nmisch@google.com> References: <8f2118b9-79e3-4af7-b2c9-bd5818193ca4@iki.fi> <8e710eaa-fcfe-4a0b-ae90-87743083e777@iki.fi> <82eb454e-f9e0-433c-89f5-69f03b09ca32@vondra.me> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/2.2.12 (2023-09-09) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Tue, Mar 04, 2025 at 05:50:34PM -0500, Andres Freund wrote: > On 2024-12-09 00:12:32 +0100, Tomas Vondra wrote: > > [23:48:44.444](1.129s) ok 3 - reserved_connections limit > > [23:48:44.445](0.001s) ok 4 - reserved_connections limit: matches > > process ended prematurely at > > /home/user/work/postgres/src/test/postmaster/../../../src/test/perl/PostgreSQL/Test/BackgroundPsql.pm > > line 154. > > # Postmaster PID for node "primary" is 198592 > > > I just saw this failure on skink in the BF: > https://buildfarm.postgresql.org/cgi-bin/show_log.pl?nm=skink&dt=2025-03-04%2015%3A43%3A23 > > [17:05:56.438](0.247s) ok 3 - reserved_connections limit > [17:05:56.438](0.000s) ok 4 - reserved_connections limit: matches > process ended prematurely at /home/bf/bf-build/skink-master/HEAD/pgsql/src/test/perl/PostgreSQL/Test/BackgroundPsql.pm line 160. > > > > That BackgroundPsql.pm line is this in wait_connect() > > > > $self->{run}->pump() > > until $self->{stdout} =~ /$banner/ || $self->{timeout}->is_expired; > > A big part of the problem here imo is the exception behaviour that > IPC::Run::pump() has: > > If pump() is called after all harnessed activities have completed, a "process > ended prematurely" exception to be thrown. This allows for simple scripting > of external applications without having to add lots of error handling code at > each step of the script: > > Which is, uh, not very compatible with how we use IPC::Run (here and > elsewhere). Just ending the test because a connection failed is pretty awful. Historically, I think we've avoided this sort of trouble by doing pipe I/O only on processes where we feel able to predict when the process will exit. Commit f44b9b6 is one example (simpler case, not involving pump()). It would be a nice improvement to do better, since there's always some risk of unexpected exit. > This behaviour makes it really hard to debug problems. It'd have been a lot > easier to understand the problem if we'd seen psql's stderr before the test > died. > > I guess that mean at the very least we'd need to put an eval {} around the > ->pump() call., print $self->{stdout}, ->{stderr} and reraise an error? That sounds right. Officially, you could call ->pumpable() before ->pump(). It's defined as 'Returns TRUE if calling pump() won't throw an immediate "process ended prematurely" exception.' I lack high confidence that it avoids the exception, because the pump() still calls pumpable()->reap_nb()->waitpid(WNOHANG) and may decide "process ended prematurely" based on the new finding. In other words, I bet there would be a TOCTOU defect in "$h->pump if $h->pumpable". > Presumably not just in in wait_connect(), but also at least in pump_until()? If the goal is to have it capture maximum data from processes that exit when we don't expect it (seems good to me), yes.