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 1tadVE-003h2h-6J for pgsql-hackers@arkaria.postgresql.org; Wed, 22 Jan 2025 16:22:52 +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 1tadVC-001is8-VR for pgsql-hackers@arkaria.postgresql.org; Wed, 22 Jan 2025 16:22:50 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tadVC-001irs-ML for pgsql-hackers@lists.postgresql.org; Wed, 22 Jan 2025 16:22:50 +0000 Received: from mail-il1-x135.google.com ([2607:f8b0:4864:20::135]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1tadVA-000w6f-0i for pgsql-hackers@postgresql.org; Wed, 22 Jan 2025 16:22:49 +0000 Received: by mail-il1-x135.google.com with SMTP id e9e14a558f8ab-3ce87e92906so23508765ab.2 for ; Wed, 22 Jan 2025 08:22:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737562968; x=1738167768; darn=postgresql.org; h=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=hdq8drs5j54rGlcRKcdc/YpjSHdpSpre389qPvAhv1A=; b=K2o06ImPMMw8j7Os3QCAL33kvCesyAGrnJyl0pBPKLDwLGjLWMJwvYYFC08Hh2nLoW OhdoFA+QoYu4m+YAEHOgYv+dpnaJLrZCMZkeFAM1qTYl583AtRoGLlTpSXvr5oJFqDPE jcBiomJs5WPBDvLgylVG5yOR3u1RTx0FPncRcBYwAMCIakMVmZLlZ7BEwbfnYVxn+lAV nZLqUK77Xh3XMxCVXCFQ4CdkiFz709jlb9Sa1pmYYvXB3/Rl4qTiCF0t2wsvuK4O80Mg QA3x0LkaPbAHUnrjThqpkKqjrFtUV+c3uX3liV/8JwhMuHeLfaKGFHES9jaNFSntkSmT D8Bw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737562968; x=1738167768; h=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=hdq8drs5j54rGlcRKcdc/YpjSHdpSpre389qPvAhv1A=; b=ZZxldl2lR2+F+rIij7qr/mWYOPH7fcR7sWwCwOML4qJAq+SHRgH+SRXE8fzl4Xq2bY L5HMwEj3YC8SIl+bGzpNavdLRcs8XmSi02g4TCcLiHbMXL7PfnKY6zGqBEExUXRGPQ45 ys+GUzPBlggOiVEB6LKT+CjodulYEgKm1vamwGv/FLG8SHnlyAKWO8WG+wor0g9r6T01 841Ff7kTzker208Px/DGkv76JCYYheGErq+NbSxUEBQSxnq8WpTMZxKT0cd/SO8NX86U oqbh1bz35gsJoxIzWZhRWTqHt9FR7XOVn7WzNuwyYaHILWa8b6snn1Vdm2JPopoq+OeR eJAQ== X-Gm-Message-State: AOJu0YwKhUOO82v+E90OeKv6C/cFJ63R56aI06+digGR9zaYQLmFUaeZ irxcjO8X248q7hy9mMadmrYZfrdV19BF83GnYfbb42AMg0N3zt4NfW0XUw== X-Gm-Gg: ASbGnctxhUO+Jczkc/o4Rm1CH/3+r34ixmRxZ3FkHB+yslOcY+sy+OXRCp1FTNiNHUG IHMK0EaFqwuxR7lDa7cF0Z9ewVVGf1LvimWdW4qhqzCYwJC0Qafb2oRQlHCyBbD1suZXKzWlFQQ w9qehFB3xp11IwKjV3NI7VSro1Ff86R01wyDYGUu+iT0VWcpzFcm0tDAuFZMhJfoOXFowpvv4Jq Ea/ipM4Pl0ubo7iOal7xkaSskBBJGCkSjgcbK5KZoWgk57TlTdb6kNgR4Rt3cFd9FfVhId9Dvz5 zd8+ZVopz9T8xQ9plXBKH5K18BE40/ARcJzisMJJgXXwgBysx1rgOvPyUMdM X-Google-Smtp-Source: AGHT+IFLewrLDCbMCspFBIMJDC9VMLyF8V7d+wrOk343HYRKRVlXq4G/kEqmiddEuns1F2b0xqfgbQ== X-Received: by 2002:a05:6e02:20c8:b0:3ce:9149:a8b1 with SMTP id e9e14a558f8ab-3cf743e94f7mr166058715ab.9.1737562967963; Wed, 22 Jan 2025 08:22:47 -0800 (PST) Received: from nathan (162-195-168-172.lightspeed.stlsmo.sbcglobal.net. [162.195.168.172]) by smtp.gmail.com with ESMTPSA id e9e14a558f8ab-3cfb1ef5ca1sm6834555ab.13.2025.01.22.08.22.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Jan 2025 08:22:47 -0800 (PST) Date: Wed, 22 Jan 2025 10:22:45 -0600 From: Nathan Bossart To: Paul Ramsey Cc: PostgreSQL Hackers Subject: Re: Converting pqsignal to void return Message-ID: References: <4E796D56-79B5-4447-9DA7-5428BC1A6B53@cleverelephant.ca> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <4E796D56-79B5-4447-9DA7-5428BC1A6B53@cleverelephant.ca> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Wed, Jan 22, 2025 at 07:57:52AM -0800, Paul Ramsey wrote: > I just ran across this change when a bunch of CI´s I run barfed. Oops, sorry. > The problem we are having in extension land is that we often run > functions in external libraries that take a long time to return, and we > would like to ensure that PgSQL users can cancel their queries, even when > control has passed into those functions. > > The way we have done it, historically, has been to take the return value > of pqsignal(SIGINT, extension_signint_handler) and remember it, and then, > inside extension_signint_handler, call the pgsql handler once we have > done our own business.. I see a couple other projects that might be doing something similar [0]. > It is possible we have been Doing It Wrong all this time, and would love > some pointers on the right way to do this. > > Alternatively, if we have a valid use case, it would be nice to have the > return value from pqsignal() back. I don't think you were doing it wrong before, but commit 3b00fdb did add some weird race conditions to the return value, but only in rare cases that I don't think apply to the case you shared. I was tempted to suggest that you try using sigaction() with the second "act" argument set to NULL to retrieve the original signal handler, but I think there's a good chance you'd get our wrapper_handler() function (we store the actual handlers in a separate array), which is no good. So, I should probably just revert d4a43b2. An alternative approach could be to provide our own way to retrieve the current handler, but that comes with its own race conditions, although perhaps those are more obvious than the pqsignal() ones. WDYT? [0] https://codesearch.debian.net/search?q=%3D+pqsignal&literal=1 -- nathan