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 1sRvoE-002BOT-4G for pgsql-hackers@arkaria.postgresql.org; Thu, 11 Jul 2024 15:34:14 +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 1sRvoC-00FWUi-Ha for pgsql-hackers@arkaria.postgresql.org; Thu, 11 Jul 2024 15:34:12 +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 1sRvoC-00FWUa-55 for pgsql-hackers@lists.postgresql.org; Thu, 11 Jul 2024 15:34:12 +0000 Received: from mail-io1-xd35.google.com ([2607:f8b0:4864:20::d35]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1sRvoA-001Zyk-39 for pgsql-hackers@postgresql.org; Thu, 11 Jul 2024 15:34:11 +0000 Received: by mail-io1-xd35.google.com with SMTP id ca18e2360f4ac-7f38da3800aso39293239f.0 for ; Thu, 11 Jul 2024 08:34:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720712048; x=1721316848; darn=postgresql.org; h=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=UeIbUJscJX2UBv/TGwLhI93Tdqf7Uc/3lZ2D96p884M=; b=iwjqY3ryjXOZEAEhYyiVc4VfXBiHRpNpZ4WBrDD01RWFFnJ12AOryoOnJFqcHHMmOS xsAaPb/QvD2rU8Xm6MXGQYPPGyr3PovEoQ2eOQpLWUJd3LyGDjWQ9A18RHcGX7Y5EI2f DrOjcHA3P+kOQkAB2tfQ8E5GhYHIuXdcDuj6XbttHGFRbMVk25UnxoxO8hRHfDszrEGe qAtOysw2a+OP/3jSa/Yl6S+mv+pVsR9Xe5Uls+Ib3hP8GiDh/uoUmYJwC72Oi+ZitMuu qZ+BTXg+gRW0Jhy22kmIAFrdbOhUG4kXvRQ1DTEgBOsXV5oQfeKXmYhqXBOklFaklg6q ZDOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720712048; x=1721316848; h=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=UeIbUJscJX2UBv/TGwLhI93Tdqf7Uc/3lZ2D96p884M=; b=Aj8rrSfJMKhn8uD1hdulGgb0+R6xppGpO4jQdfJES8WzAAc85kbbGeoBqpA7qd6MvK wIJbzGXrnRAtyiAUOMdrE7iVr+r+/Z1hMAHBZ0w+wrRz+1Btq0oOAsQyvpsjmythp4GE 7pWsfQorgeIfyCtWto1+JfhXVZ6JynPajW826Me4Fm1U5iYKr4fwv4Ls5G/Ntk6KVhpk RU9wFbZ3fE7gj4fNUvYu2HPp+IAu+eYN/sg4uK77m3knYUcYm5/ytBf2VdGwesC4knwY 2epwNLoPQbnpqhVOANqtzT8wq4gj1P9alPGLj8HsoIYzlIDqExy4ZGec5/zuZs1YOWyu r5hQ== X-Forwarded-Encrypted: i=1; AJvYcCW2IIvh2K2BrdYYcE5rXhDC00GRessAbw6QYgQt59XHNBjfftgPkOnLMqe7slJeqJpOWdx4EyJQkpZQGEDmg75JtbIkYFEb6rfPUsA+ X-Gm-Message-State: AOJu0YyDP+f3Typqd0LZvvq06+uzrhXB6N/s1FhsUofs/joR5LZlAFZA is31QmcqLcx5ulF10aexZJljepdvEvpUlO/3Zcy1FTQaSov11iyn X-Google-Smtp-Source: AGHT+IFCaFm8vZ0zY7FcF1XMmpo0v5+MvUF/m2/OZsCL9+0eYUgG/yQbuVbWno88SaBLa33LntO/Yw== X-Received: by 2002:a5e:a714:0:b0:7f8:c0ed:b5a6 with SMTP id ca18e2360f4ac-8000000c442mr1033425139f.5.1720712048088; Thu, 11 Jul 2024 08:34:08 -0700 (PDT) Received: from nathan (162-195-168-172.lightspeed.stlsmo.sbcglobal.net. [162.195.168.172]) by smtp.gmail.com with ESMTPSA id 8926c6da1cb9f-4c0b1af80fdsm1854587173.32.2024.07.11.08.34.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jul 2024 08:34:07 -0700 (PDT) Date: Thu, 11 Jul 2024 10:34:06 -0500 From: Nathan Bossart To: Sami Imseih Cc: Bertrand Drouvot , Tom Lane , Robert Haas , "pgsql-hackers@postgresql.org" Subject: Re: Restart pg_usleep when interrupted Message-ID: References: <01000190606e3d2a-116ead16-84d2-4449-8d18-5053da66b1f4-000000@email.amazonses.com> <7D50DC5B-80C6-47B5-8DA8-A6C68A115EE5@gmail.com> <2100439.1719610468@sss.pgh.pa.us> <373D199B-2312-431D-8018-F2808913F979@gmail.com> <3712E898-03DA-4E03-AF51-D3E24DE68216@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk + /* + * We allow nanosleep to handle interrupts and retry with the remaining time. + * However, since nanosleep is susceptible to time drift when interrupted + * frequently, we add a safeguard to break out of the nanosleep whenever the + * total time of the sleep exceeds the requested sleep time. Using nanosleep + * is a more portable approach than clock_nanosleep. + */ I'm curious why we wouldn't just subtract "elapsed_time" from "delay" at the bottom of the while loop to avoid needing this extra check. Also, I think we need some commentary about why we want to retry after an interrupt in this case. -- nathan