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 1sLgxI-00G3Pu-HM for pgsql-hackers@arkaria.postgresql.org; Mon, 24 Jun 2024 10:29:49 +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 1sLgxG-008LGc-QP for pgsql-hackers@arkaria.postgresql.org; Mon, 24 Jun 2024 10:29:47 +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 1sLgxG-008LGM-Ds for pgsql-hackers@lists.postgresql.org; Mon, 24 Jun 2024 10:29:46 +0000 Received: from meesny.iki.fi ([195.140.195.201]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sLgxD-002s8Q-IH for pgsql-hackers@postgresql.org; Mon, 24 Jun 2024 10:29:45 +0000 Received: from [192.168.1.115] (dsl-hkibng22-54f8db-125.dhcp.inet.fi [84.248.219.125]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: hlinnaka) by meesny.iki.fi (Postfix) with ESMTPSA id 4W742q4B6lzyVQ for ; Mon, 24 Jun 2024 13:29:39 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=meesny; t=1719224979; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=8OniLoN1Euxv0dYjd1APK/mKqeVoZ3oMxUZcKqcaZvQ=; b=nfJfwzBBJdIq91t7t/VIyLcs8kT0IyQIoLr4ifrkgGaeccKtNZvZbpN2mzpOOfoHWxTefV g3ZpSOiAcSVpPjut+K6pHroxzPUUvTKfCNvKWyToeJUP4JexqhGWXpAJp2BMY7Fa8w5+Oi S8VDcBdn0w7lz393nE8fS682arS1PX4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=meesny; t=1719224979; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=8OniLoN1Euxv0dYjd1APK/mKqeVoZ3oMxUZcKqcaZvQ=; b=S1TysMxrduqwITrHUzHAixvGwUZK+yVehIVF07bJ0jl0DGuyMRpHHd0O/1tuITltsxUmxX 2yMlsxy9C8KvntX+JmXTdWBBqXGFPcHwyRr9D5C7s4nfN6sEXSpXsfE6nlS2DSMVGuDZDL hZCol9K1Ta7Nxl858cWooOQOh4em9JE= ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.auth=hlinnaka smtp.mailfrom=hlinnaka@iki.fi ARC-Seal: i=1; s=meesny; d=iki.fi; t=1719224979; a=rsa-sha256; cv=none; b=K6cydeT2Vx4bp95ZAil96+goymuNxuLa4c8A9oZU1PRUqTwraLm8e2YKl0uruYiwJRHF8D COkSSNjQGxgkdekJQLbs45zucH89JNm060svcHBSJs2vVKz/oWIX41KND0/PhIgqSyirhT EgHW3eLkzNhLXU4fr6/R/kk4eswD5iY= Message-ID: Date: Mon, 24 Jun 2024 13:29:38 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US From: Heikki Linnakangas Subject: Injection point locking To: pgsql-hackers Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk InjectionPointRun() acquires InjectionPointLock, looks up the hash entry, and releases the lock: > LWLockAcquire(InjectionPointLock, LW_SHARED); > entry_by_name = (InjectionPointEntry *) > hash_search(InjectionPointHash, name, > HASH_FIND, &found); > LWLockRelease(InjectionPointLock); Later, it reads fields from the entry it looked up: > /* not found in local cache, so load and register */ > snprintf(path, MAXPGPATH, "%s/%s%s", pkglib_path, > entry_by_name->library, DLSUFFIX); Isn't that a straightforward race condition, if the injection point is detached in between? Another thing: I wanted use injection points to inject an error early at backend startup, to write a test case for the scenarios that Jacob point out at https://www.postgresql.org/message-id/CAOYmi%2Bnwvu21mJ4DYKUa98HdfM_KZJi7B1MhyXtnsyOO-PB6Ww%40mail.gmail.com. But I can't do that, because InjectionPointRun() requires a PGPROC entry, because it uses an LWLock. That also makes it impossible to use injection points in the postmaster. Any chance we could allow injection points to be triggered without a PGPROC entry? Could we use a simple spinlock instead? With a fast path for the case that no injection points are attached or something? -- Heikki Linnakangas Neon (https://neon.tech)