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 1s4uGL-001qFM-NM for pgsql-hackers@arkaria.postgresql.org; Thu, 09 May 2024 03:16:05 +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 1s4uGJ-004HWo-81 for pgsql-hackers@arkaria.postgresql.org; Thu, 09 May 2024 03:16:03 +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 1s4uGI-004HWg-MX for pgsql-hackers@lists.postgresql.org; Thu, 09 May 2024 03:16:03 +0000 Received: from mail-ot1-x335.google.com ([2607:f8b0:4864:20::335]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1s4uGE-0007OM-7Z for pgsql-hackers@postgresql.org; Thu, 09 May 2024 03:16:01 +0000 Received: by mail-ot1-x335.google.com with SMTP id 46e09a7af769-6f0794fdb95so258362a34.2 for ; Wed, 08 May 2024 20:15:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=leadboat.com; s=google; t=1715224557; x=1715829357; darn=postgresql.org; h=user-agent: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=ZHwdNhqmPGYSFf4hdSAe4oEjVxkyczmKeNxpB2H/XmE=; b=AhwoluLRX/WKDIAhVAVnecbWOO4JSljfrHeM1EdUMOx8ZHSFoHKNHfr1JVOPpGQkrm s9rY1QkijKRU8voUdGsNuMnu/0KApA34IuSV6sSI15PshfsGNKNcPzrUE1Wx2pHZ1gpJ uqCDKlQuFs9xr9p0G1/rdSPN0sfAEuzaE/bj8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715224557; x=1715829357; h=user-agent: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=ZHwdNhqmPGYSFf4hdSAe4oEjVxkyczmKeNxpB2H/XmE=; b=TX4IfmDd4kd6Aoy3X641oQ3/rnS1rRDk7w4MpDC8v+QTD84aJswZ8CxPOl/QPa7YFn lN3lDCxio5RpZ1ngTxZ87SKrXUb9FkqqEGSdIO3JmE0p6bmVcPHB8sXg0ZlKwTjNBtvg ljISbJiRbQsUwZHekMJ08+7ufQvCM3BE9aqDaQ3MwAT9pjeapIZWgWo8k1yYpujVHQs7 JMtAq4P+MeN0qugaSG50HdBTBxRjgw6LGthzguBcpzs/ZIk60zJ+Ms4I/Jqqp1jMmHOp fmzaJvnNsl8i2BB6+pxn98K2/L7aPGRuBfWIQAlVqq7IDGfHJ7mBXNl52cXlIAae4q4Q dBqg== X-Forwarded-Encrypted: i=1; AJvYcCU1v4uxM9IsF4glEqO+eMdP2W7nVL1nME8QNkteXIvv3sFIMIWoj+Wnbs/wtoJ7ftqQavPIN9i2H1Y3uivpAS6mx9lXXlCRpcVaD5GV X-Gm-Message-State: AOJu0YwDF//1dx5HbA23bpC0mBqsxIQq9tJ7Old9qiifyQ64PYG3WdOy h7DBGsMB5WQv3Uxg8H16/ZoBxJaFOJQYddTTyB/np8+efYVUoGoKwHndSaCBEA== X-Google-Smtp-Source: AGHT+IEPgarOTFzq0N+yCBKbUfeDcPuQUHH7GovhRa2y5lPPMMCbRxK+UppoHewpLwaAPIgdTWMJ/w== X-Received: by 2002:a05:6830:3b04:b0:6ee:203f:b877 with SMTP id 46e09a7af769-6f0b7828463mr4245018a34.4.1715224556944; Wed, 08 May 2024 20:15:56 -0700 (PDT) Received: from rfd.leadboat.com ([2600:1702:a20:5750::48]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-6f0e022bf24sm102319a34.68.2024.05.08.20.15.55 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 May 2024 20:15:56 -0700 (PDT) Date: Wed, 8 May 2024 20:15:53 -0700 From: Noah Misch To: Michael Paquier Cc: Heikki Linnakangas , Tom Lane , pgsql-hackers Subject: Re: Weird test mixup Message-ID: <20240509031553.47@rfd.leadboat.com> References: <20240501231214.40@rfd.leadboat.com> <20240502193555.a1.nmisch@google.com> <20240506212324.2e.nmisch@google.com> <20240507185310.d3@rfd.leadboat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/2.2.12 (2023-09-09) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Thu, May 09, 2024 at 09:37:54AM +0900, Michael Paquier wrote: > On Tue, May 07, 2024 at 11:53:10AM -0700, Noah Misch wrote: > > The problem I'm trying to tackle in this thread is to make > > src/test/modules/gin installcheck-safe. $SUBJECT's commit 5105c90 started > > that work, having seen the intarray test suite break when run concurrently > > with the injection_points test suite. That combination still does break at > > the exit-time race condition. To reproduce, apply this attachment to add > > sleeps, and run: > > > > make -C src/test/modules/gin installcheck USE_MODULE_DB=1 & sleep 2; make -C contrib/intarray installcheck USE_MODULE_DB=1 > > Thanks for that. I am not really sure how to protect that without a > small cost in flexibility for the cases of detach vs run paths. This > comes down to the fact that a custom routine could be run while it > could be detached concurrently, removing any stuff a callback could > depend on in the module. > > It was mentioned upthread to add to InjectionPointCacheEntry a fixed > area of memory that modules could use to store some "status" data, but > it would not close the run/detach race because a backend could still > hold a pointer to a callback, with concurrent backends playing with > the contents of InjectionPointCacheEntry (concurrent detaches and > attaches that would cause the same entries to be reused). > One way to close entirely the window would be to hold > InjectionPointLock longer in InjectionPointRun() until the callback > finishes or until it triggers an ERROR. This would mean that the case > you've mentioned in [1] would change, by blocking the detach() of s3 > until the callback of s2 finishes. > [1] https://www.postgresql.org/message-id/20240501231214.40@rfd.leadboat.com Yes, that would be a loss for test readability. Also, I wouldn't be surprised if some test will want to attach POINT-B while POINT-A is in injection_wait(). Various options avoiding those limitations: 1. The data area formerly called a "status" area is immutable after attach. The core code copies it into a stack buffer to pass in a const callback argument. 2. InjectionPointAttach() returns an attachment serial number, and the callback receives that as an argument. injection_points.c would maintain an InjectionPointCondition for every still-attached serial number, including global attachments. Finding no condition matching the serial number argument means detach already happened and callback should do nothing. 3. Move the PID check into core code. 4. Separate the concept of "make ineligible to fire" from "detach", with stronger locking for detach. v1 pointed in this direction, though not using that terminology. 5. Injection point has multiple callbacks. At least one runs with the lock held and can mutate the "status" data. At least one runs without the lock. (1) is, I think, simple and sufficient. How about that?