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 1rXoHI-00ClzJ-Kw for pgsql-hackers@arkaria.postgresql.org; Wed, 07 Feb 2024 20:12:17 +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 1rXoHH-00D5sL-K9 for pgsql-hackers@arkaria.postgresql.org; Wed, 07 Feb 2024 20:12:15 +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 1rXoHH-00D5sD-9D for pgsql-hackers@lists.postgresql.org; Wed, 07 Feb 2024 20:12:15 +0000 Received: from mail-il1-x12e.google.com ([2607:f8b0:4864:20::12e]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rXoHE-005azt-OA for pgsql-hackers@postgresql.org; Wed, 07 Feb 2024 20:12:14 +0000 Received: by mail-il1-x12e.google.com with SMTP id e9e14a558f8ab-363b6848f95so4342405ab.3 for ; Wed, 07 Feb 2024 12:12:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707336732; x=1707941532; 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=BgTQkoeKdQWH6eHTTeeS+DHDUJKC/kCALcbWfhnwduE=; b=eqnbJGHJcNznX6J8srRzK67MbvvbnbG4aVOP7yiy/MbFWiNDujQOlhifgHU/VoLDuh 2GlQOob4/J/6Kyc2ZuzaWuO6cK7imerdYEU9W4J1/H/lsw5+q1TjBP47mh5xBsmoEcNS +I/62cTmIVHd+69QXO2UgjK8MBZhBoQe8/XrBKhKKsd45pRFhnzwTfVjkcpWAaQoAK9L JpTi6uYDcJrFsm8MOj025AQAcmbHiNCwIpH3yRIqjSdmow8oTnAcSSss0bE7JCSCWl4f g0Y1ATe0Uzti9ffZiBvCxH+vqhn9bU54XwHJgSXZoBpGubbpZ2LysQdh5VnR4jaZGbps qffQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707336732; x=1707941532; 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=BgTQkoeKdQWH6eHTTeeS+DHDUJKC/kCALcbWfhnwduE=; b=cnbCXf6ojb4IdKtbG+Rs/2b3ID6jLC37qdmonz8GdC5xzjycXHsEbNdsF172eC9TcU hFxVbX1rHx3RAniyHCYQ0hRtyonhVvqc6mSA+4pasl0m4nrCVVNXwTrcxRywKYMu4TDb RSEBwuvemW7pUJ0enidjP8w+ZrrIQH/mKr2pxwOA3hlMSJpDqQBxXDvghbuCZNHzvx2v +mfjFW49CHgNjoJqw5AJnTg5UHWWzIW/meGj1nw6ilJkfHhwdsFWfbCY/XZNUoHYcrpz 0YLvNfvUWmIldY3tVZg70r8RlAPXyIC+28jZtFpHmNpPVmdIYkZbBcTmuIh5geRhXaSc IUgg== X-Forwarded-Encrypted: i=1; AJvYcCU7IdHtl7R18rfQmg5aHNms2YskqvqY5dD8l/c8bj3SWeH8W2lrDSAmVzxdfAlpCGkDSeoePSbmfQCOJsQTx6yNMSPNYxKmWZjMQZYm X-Gm-Message-State: AOJu0Yxd7eVBBa7PHGdPcKGBWhCudC7hEYG8WYcZKk2HcdtyP+CZMSAJ a5rXH9q8eObpGRuc3wmvPQMatxY3p4TgbvbQOr4BePWjJbIi5E6B X-Google-Smtp-Source: AGHT+IFQXJAtk8qmRVDQJQ0qutkGpzyQ+jrrDkyFqHyVAk6RI16KWIf25ky0hjdeu40AKwlCV7OWLQ== X-Received: by 2002:a05:6e02:481:b0:363:d9fb:6147 with SMTP id b1-20020a056e02048100b00363d9fb6147mr4065403ils.29.1707336731668; Wed, 07 Feb 2024 12:12:11 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCUetrS5vvfME4k1xtKdvAO7alBQmHJCF9Myg+QzYrFrE1aLoE4aaZW0tzPz0HKZgLkANOEYQ9ryCuJmn1g7gxJf5VjFQjK/IZuy5sKfRmijfEp3Fa7gFTB6E8PblbrGSJOwgQgxsyKk6eg6lbYHG5BEhHOPWl+p Received: from nathanxps13 (162-195-168-172.lightspeed.stlsmo.sbcglobal.net. [162.195.168.172]) by smtp.gmail.com with ESMTPSA id t34-20020a05663836e200b0047150f68f66sm409726jau.74.2024.02.07.12.12.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 12:12:11 -0800 (PST) Date: Wed, 7 Feb 2024 14:12:08 -0600 From: Nathan Bossart To: Andres Freund Cc: Andy Fan , pgsql-hackers@postgresql.org, noah@leadboat.com, Robert Haas Subject: Re: common signal handler protection Message-ID: <20240207201208.GA279677@nathanxps13> References: <20231121212008.GA3742740@nathanxps13> <20240207023941.GA67817@nathanxps13> <20240207024853.pg55gxzmqxi3nrmr@awork3.anarazel.de> <20240207170650.GA80671@nathanxps13> <20240207171554.GA153000@nathanxps13> <20240207184050.rkvpuudq7huijmkb@awork3.anarazel.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240207184050.rkvpuudq7huijmkb@awork3.anarazel.de> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Wed, Feb 07, 2024 at 10:40:50AM -0800, Andres Freund wrote: > On 2024-02-07 11:15:54 -0600, Nathan Bossart wrote: >> Perhaps we should add a file global bool that is only set during >> wrapper_handler(). Then we could Assert() or elog(ERROR, ...) if >> pqsignal() is called with it set. > > In older branches that might have been harder (due to forking from a signal > handler and non-fatal errors thrown from signal handlers), but these days I > think that should work. > > FWIW, I don't think elog(ERROR) would be appropriate, that'd be jumping out of > a signal handler :) *facepalm* Yes. > If it were just for the purpose of avoiding the issue you brought up it might > not quite be worth it - but there are a lot of things we want to forbid in a > signal handler. Memory allocations, acquiring locks, throwing non-panic > errors, etc. That's one of the main reasons I like a common wrapper signal > handler. > > Which reminded me of https://postgr.es/m/87msstvper.fsf%40163.com - the set of > things we want to forbid are similar. I'm not sure there's really room to > harmonize things, but I thought I'd raise it. > > Perhaps we should make the state a bitmap and have a single > AssertNotInState(HOLDING_SPINLOCK | IN_SIGNALHANDLER) Seems worth a try. I'll go ahead and proceed with these patches and leave this improvement for another thread. -- Nathan Bossart Amazon Web Services: https://aws.amazon.com