Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1ihmzs-0004YR-EG for pgsql-bugs@arkaria.postgresql.org; Thu, 19 Dec 2019 04:01:08 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1ihmyt-0007xT-9j for pgsql-bugs@arkaria.postgresql.org; Thu, 19 Dec 2019 04:00:07 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1ihmys-0007xM-Vo for pgsql-bugs@lists.postgresql.org; Thu, 19 Dec 2019 04:00:07 +0000 Received: from mail-lf1-x143.google.com ([2a00:1450:4864:20::143]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1ihmyp-0008E4-Se for pgsql-bugs@lists.postgresql.org; Thu, 19 Dec 2019 04:00:06 +0000 Received: by mail-lf1-x143.google.com with SMTP id l18so3307441lfc.1 for ; Wed, 18 Dec 2019 20:00:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language; bh=eiMwp/h+FrGvSNj/rUyklVqA+q+3vPohiqZw+DsGChg=; b=Wj11yUc8hmkLzlxTXI8SrVZq8X/IREf6OC6yGKxb++2MaP1YoOEc2JcSSvtUITK+3K mcNgU91x27wuQ9WjOifISmBoktnTSafdp1zMLOuX2krTWvbKeXYRKWos3qvYyUIEG/0J hkqA0Oyi3mH+RTwp/7VQY056AO3i5cn0WKovWIwO+kjK00NsfzJpfqTzf/4weEPKR08p i8T7H7581qKDcLfchGSMSx/RKUCy3jyii2AUPLxuQm4WiWDBQfW9BDFby7ebXHsdmaSh mc/+yYMad9fx5n8jhMpSCrVz0a3s1dYfcWFlAVJGqFeip5PG5umfi+lm1LDUf+YmR+ZT VAfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language; bh=eiMwp/h+FrGvSNj/rUyklVqA+q+3vPohiqZw+DsGChg=; b=oRGDliCsz0UyaHdeQ7aENNRgUPaymuoyad1mxz5ciazGu7n9uNgxcW55XtKGwEhWiX 1HwBrvpc4tZR/RtfrAyj9QOQFQAXaDy7X112Iald5eqHXUxHDDTYie7szGVIszm9QWiE /DpWoDwrG7PCzcO3YQVnTaBFqlSDdsmKM/AJdDnLYNW4OFlPV07aPspDqqAPr2YKZHCy j/gwqQkHMUzL2oeVh10BPbczexFBOgNTFCjB1SGpd5+DASnAOK0aXPkQ+2FX7/qRyhkJ kMbrRaLLp42bXI9Xc2MdfIJLAKtH0np6/KnwFGDEPcukVE+yFfnjgGca3dkFpXqrGZW6 WcUw== X-Gm-Message-State: APjAAAWiMJO7t2tzpJUhUCzqUCnCUPnA+swu4f2ORFnGjNPA1bUH7ohc T9IZ5uYZWjU4YeoFlU1y+YL1AuFy X-Google-Smtp-Source: APXvYqyibDeguyFWqvsE4jxb7Vh/fZOoiqBvGCxaUiStlO+T964N4B2Xp4W8cKojt68pm+xq/AnqJA== X-Received: by 2002:a19:5057:: with SMTP id z23mr3886245lfj.132.1576728002720; Wed, 18 Dec 2019 20:00:02 -0800 (PST) Received: from [1.0.0.7] ([178.155.4.214]) by smtp.gmail.com with ESMTPSA id g15sm2042665ljk.8.2019.12.18.20.00.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 18 Dec 2019 20:00:01 -0800 (PST) Subject: Re: BUG #16161: pg_ctl stop fails sometimes (on Windows) To: Kyotaro Horiguchi , tgl@sss.pgh.pa.us Cc: pgsql-bugs@lists.postgresql.org References: <4741.1576684991@sss.pgh.pa.us> <26441.1576706955@sss.pgh.pa.us> <20191219.103948.2182167132387989763.horikyota.ntt@gmail.com> From: Alexander Lakhin Message-ID: Date: Thu, 19 Dec 2019 07:00:00 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.2 MIME-Version: 1.0 In-Reply-To: <20191219.103948.2182167132387989763.horikyota.ntt@gmail.com> Content-Type: multipart/mixed; boundary="------------2DEAC356BBAF8C89B2F2C5AF" Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This is a multi-part message in MIME format. --------------2DEAC356BBAF8C89B2F2C5AF Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit 19.12.2019 4:39, Kyotaro Horiguchi wrote: > At Wed, 18 Dec 2019 17:09:15 -0500, Tom Lane wrote in >> Alexander Lakhin writes: >>> So I see three ways now: >>> 1) Revert the pgwin32_open change and choose the previously rejected >>> approach: Unlink postmaster.pid using rename operation (adopt the >>> solution from https://stackoverflow.com/questions/3764072/). >>> 2) Add a check for directory in pgwin32_open, but I think then we're >>> getting close to checking there just for postmaster.pid. >>> 3) Find out how often we get ERROR_ACCESS_DENIED during all regression >>> tests and if such error count is near zero, then add the check for isdir >>> in fsync_fname_ext and friends, and get done. >> I'm not terribly thrilled with (1) because I do not think that >> postmaster.pid accesses are the only place where we have this issue. >> And (3) is not only not a forward-looking solution, but it imagines >> that the speed of the regression tests is the only thing we need to >> worry about here. We generally don't assume that the regression >> tests are an accurate model of the performance users will see. >> >> So that leaves us with (2), it seems. > Agreed for (2). > > I'm not sure about the point of the discussion that stat()'ing is > messy. If it's about performance, does stat()ing only when CreateFile > returned ERROR_ACCESS_DENIED helps? Anyway we wait for a moment in > that case. Please look at the patch that implements (2). It makes `vcregress recoverycheck` pass (and my demo restart test still passes too). As open(dir) is getting a little more expensive than before, maybe it's still worthwhile to patch fsync*(..., isdir,...). I can prepare such a patch if so. Best regards, Alexander --------------2DEAC356BBAF8C89B2F2C5AF Content-Type: text/x-patch; name="improve-eacces-handling.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="improve-eacces-handling.patch" diff --git a/src/port/open.c b/src/port/open.c index 51652762a1..2196cbc992 100644 --- a/src/port/open.c +++ b/src/port/open.c @@ -144,11 +144,19 @@ pgwin32_open(const char *fileName, int fileFlags,...) */ if (err == ERROR_ACCESS_DENIED) { - if (loops < 10) - { - pg_usleep(100000); - loops++; - continue; + /* + * We don't want to retry fopen() with a directory, + * which is known to fail with the same ERROR_ACCESS_DENIED error + * (Windows NT status code STATUS_FILE_IS_A_DIRECTORY). + */ + struct stat st; + if (stat(fileName, &st) != 0 || !S_ISDIR(st.st_mode)) { + if (loops < 10) + { + pg_usleep(100000); + loops++; + continue; + } } } --------------2DEAC356BBAF8C89B2F2C5AF--