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 1snLAq-002oCL-Kt for pgsql-hackers@arkaria.postgresql.org; Sun, 08 Sep 2024 16:54:05 +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 1snLAq-00GUUW-7E for pgsql-hackers@arkaria.postgresql.org; Sun, 08 Sep 2024 16:54:04 +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 1snLAp-00GUSJ-LM for pgsql-hackers@lists.postgresql.org; Sun, 08 Sep 2024 16:54:03 +0000 Received: from mail-pl1-x62a.google.com ([2607:f8b0:4864:20::62a]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1snLAl-000AST-3M for pgsql-hackers@postgresql.org; Sun, 08 Sep 2024 16:54:02 +0000 Received: by mail-pl1-x62a.google.com with SMTP id d9443c01a7336-2068acc8b98so32284625ad.3 for ; Sun, 08 Sep 2024 09:53:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=leadboat.com; s=google; t=1725814438; x=1726419238; darn=postgresql.org; h=user-agent:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=J2CftPDw9JOMpFvlPSEeyIgcu7EZggaARLRmzBnkmiQ=; b=SauYrRQkKMfiiR6uJDkHIAjoybOPx+XH2RMgOk/hgj0fwc2Bf76Bqm08P4DV83jSSA wljOZr/GiXNyL28kP6zW85VjTr1HqgR/TeGchBlYlctjKSD6yClMSC905pG0ACg3q2Y5 uML+fbAkrGgn7H2HB/GIhLiMrBxXCDWb2wuL0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725814438; x=1726419238; h=user-agent:in-reply-to:content-transfer-encoding :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=J2CftPDw9JOMpFvlPSEeyIgcu7EZggaARLRmzBnkmiQ=; b=cjgGrdh/9HbgMbz2X+tB7ZLXPACBiucG4z+YOqrFLPbQMA6oEOTAuCihHNaWvQUN1V 54lcb51jcbR0S87DzOEpmvo38bH7AJ+4csD6JlnA/eVHMz/NndVOgZiRw9UM5SA2cxtD 7t2cPnx7LYJYcVOGConGJc5YpOgTmJ8Bh4cB2SzrT7QAn01voI9pOCt7o+9A4FmTRoYT R9AP4OH10Tx/griLnmbxnepnh5PIAobA4UDbroXdqEiqXNSxdGwdL9AwoPygNgTo7lwn PHEgWIUX2HiQk4IKfp0jef0lpHKb4Vx1N4vLvPn6vf+cd5PLKsxfwD9/HJc8TTwhBxR7 XiVA== X-Gm-Message-State: AOJu0YzNNtt0mjbYcXlOMknxzgOHQiQSlasq3S89uuFDaIDVWpCjy6j1 PQtAleHhG1qcBJxGr7qypvPCL775zlsJgWeRjfTJdH8xZcpBvQiBH8EnYsSccw== X-Google-Smtp-Source: AGHT+IF3VsK4F89KtVTUzEDKhOdvKcoHWetsIJwTdLy8rv7E8k+UR3WHmOBsBUkM+3IQbhqgTI8KTg== X-Received: by 2002:a17:903:124d:b0:206:99a8:526c with SMTP id d9443c01a7336-2070c196865mr86475885ad.41.1725814438020; Sun, 08 Sep 2024 09:53:58 -0700 (PDT) Received: from google.com ([2600:1702:a20:5750::48]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-20710e352ccsm21658135ad.111.2024.09.08.09.53.57 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 08 Sep 2024 09:53:57 -0700 (PDT) Date: Sun, 8 Sep 2024 09:53:55 -0700 From: Noah Misch To: Alexander Lakhin Cc: pgsql-hackers Subject: Re: Yet another way for pg_ctl stop to fail on Windows Message-ID: <20240908165355.93.nmisch@google.com> References: <20240907181143.11.nmisch@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit 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 Sun, Sep 08, 2024 at 06:00:00PM +0300, Alexander Lakhin wrote: > 07.09.2024 21:11, Noah Misch wrote: > > > Noah, what do you think of handling this error in line with handling of > > > ERROR_BROKEN_PIPE and ERROR_BAD_PIPE (which was done in 0ea1f2a3a)? > > > > > > I tried the following change: > > >         switch (GetLastError()) > > >         { > > >                 case ERROR_BROKEN_PIPE: > > >                 case ERROR_BAD_PIPE: > > > +               case ERROR_PIPE_BUSY: > > > and saw no issues. > > That would be a strict improvement over returning EINVAL like we do today. We > > do use PIPE_UNLIMITED_INSTANCES, so I expect the causes of ERROR_PIPE_BUSY are > > process exit and ENOMEM-like situations. While that change is the best thing > > if the process is exiting, it could silently drop the signal in ENOMEM-like > > situations. Consider the following alternative. If sig==0, just return 0 > > like you propose, because the process isn't completely gone. Otherwise, sleep > > and retry the signal, like pgwin32_open_handle() retries after certain errors. > > What do you think of that? > I agree with your approach. It looks like Microsoft recommends to loop on > ERROR_PIPE_BUSY: [1] (they say "Calling CallNamedPipe is equivalent to > calling the CreateFile ..." at [2]). I see Microsoft suggests WaitNamedPipeA() as opposed to just polling. WaitNamedPipeA() should be more responsive. Given how rare this has been, it likely doesn't matter whether we use WaitNamedPipeA() or polling. I'd lean toward whichever makes the code simpler, probably polling. > So if we aim to not only fix "pg_ctl stop", but to make pgkill() robust, > it's the way to go, IMHO. I'm not sure about an infinite loop they show, > I'd vote for a loop with the same characteristics as in > pgwin32_open_handle(). I agree with bounding the total time of each kill(), like pgwin32_open_handle() does for open(). > [1] https://learn.microsoft.com/en-us/windows/win32/ipc/named-pipe-client > [2] https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-callnamedpipea