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 1s2J7i-001ur3-Kv for pgsql-hackers@arkaria.postgresql.org; Wed, 01 May 2024 23:12:26 +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 1s2J7f-00Ehtc-Tp for pgsql-hackers@arkaria.postgresql.org; Wed, 01 May 2024 23:12:24 +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 1s2J7f-00EhtT-Ba for pgsql-hackers@lists.postgresql.org; Wed, 01 May 2024 23:12:24 +0000 Received: from mail-yw1-x1132.google.com ([2607:f8b0:4864:20::1132]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1s2J7d-00157D-G3 for pgsql-hackers@postgresql.org; Wed, 01 May 2024 23:12:23 +0000 Received: by mail-yw1-x1132.google.com with SMTP id 00721157ae682-61bb219737dso63175027b3.2 for ; Wed, 01 May 2024 16:12:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=leadboat.com; s=google; t=1714605139; x=1715209939; 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=xol6+L6Fbox+PBBC3qWpJti9ic1QqonJBkOsjz9EzD0=; b=ZZ64XGCtXq82ep8R189VAeJ5pkOYt7zMmys5IT/srFcdnG5PmGzrrq4SRzvhhEJKP/ c2imBU2IsnfF/bZcx/1j7W1ppfLQKI+49A0yepeu2kag3DLOJf/L14HC16TGOYT716tg IuMJsUmG50zPOmfFI23i9RWFnQpgQSqM9EuVg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714605139; x=1715209939; 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=xol6+L6Fbox+PBBC3qWpJti9ic1QqonJBkOsjz9EzD0=; b=FkuQ0i+TAtEqLt39k3EkmQsTrsQvf0StfowG0hsspnq83HYH0Dc7A7ov0B7z5+usgG e+qFsC8mKmIQ2J8qq9dqJOrHpXoBxdGZlZxI/dd5lusIhaf8K/zapdXUnOp0IkwEjk9t C+w6HNYFqNQwev0gvb++5QYCc+HeCqRM6nFaKsI4phE8Ktp1k6s9V0uSNtnOjyVQ42/8 H1FXsiF3QRquabhDPYg+ML+dFNOXsxY5m77lfJaUfwf+rz1TA0TzIEZ1Riqze9xDBLXU k2QN/mMrJCSLODzB4f/+AP2Tban8LV1W76WuG0uy47KcUVz9Nsnh3L3R3BHBWjXkDm59 LuJQ== X-Forwarded-Encrypted: i=1; AJvYcCXsjIFGRku2Jd8XtlxYQbXy1dnMJM/OraIQl8+ClWU8JRlNFweIY3mhBmV7eZc9KwSsotjciM7FpjyH3IPiXc9yXVRhkooFnb76AI1k X-Gm-Message-State: AOJu0Yx1dh3I/x+NjpZ9OeY2im9ULRLViclTh6xqIQMRziC2DGLlc2gm ExC20kiS3Iz8O5YtQbKBF7lIv1SYarwqtkXoFOm6YnD/P6ZakL9AQXb3pN1FJA== X-Google-Smtp-Source: AGHT+IHVGV48nexg4eWznAwqHiq2vUfSqO8IeTx1y2jdnP4Vx0/4ZQx1yhOSYu2Ro6XYgWXvU7g+Ww== X-Received: by 2002:a05:690c:6aca:b0:61b:330e:3f25 with SMTP id ij10-20020a05690c6aca00b0061b330e3f25mr3663224ywb.30.1714605137567; Wed, 01 May 2024 16:12:17 -0700 (PDT) Received: from rfd.leadboat.com ([2600:1702:a20:5750::48]) by smtp.gmail.com with ESMTPSA id l34-20020a81ad62000000b0061bebdff712sm912791ywk.130.2024.05.01.16.12.16 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 01 May 2024 16:12:16 -0700 (PDT) Date: Wed, 1 May 2024 16:12:14 -0700 From: Noah Misch To: Michael Paquier Cc: Heikki Linnakangas , Tom Lane , pgsql-hackers Subject: Re: Weird test mixup Message-ID: <20240501231214.40@rfd.leadboat.com> References: <10fd6cdd-c5d9-46fe-9fa1-7e661191309e@iki.fi> <2387221.1710454778@sss.pgh.pa.us> <2393552.1710458033@sss.pgh.pa.us> 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 While writing an injection point test, I encountered a variant of the race condition that f4083c4 fixed. It had three sessions and this sequence of events: s1: local-attach to POINT s2: enter InjectionPointRun(POINT), yield CPU just before injection_callback() s3: detach POINT, deleting the InjectionPointCondition record s2: wake up and run POINT as though it had been non-local On Sat, Mar 16, 2024 at 08:40:21AM +0900, Michael Paquier wrote: > On Fri, Mar 15, 2024 at 11:23:31AM +0200, Heikki Linnakangas wrote: > > Wrt. the spinlock and shared memory handling, I think this would be simpler > > if you could pass some payload in the InjectionPointAttach() call, which > > would be passed back to the callback function: > > > > In this case, the payload would be the "slot index" in shared memory. > > > > Or perhaps always allocate, say, 1024 bytes of working area for every > > attached injection point that the test module can use any way it wants. Like > > for storing extra conditions, or for the wakeup counter stuff in > > injection_wait(). A fixed size working area is a little crude, but would be > > very handy in practice. That would be one good way to solve it. (Storing a slot index has the same race condition, but it fixes the race to store a struct containing the PID.) The best alternative I see is to keep an InjectionPointCondition forever after creating it. Give it a "bool valid" field that we set on detach. I don't see a major reason to prefer one of these over the other. One puts a negligible amount of memory pressure on the main segment, but it simplifies the module code. I lean toward the "1024 bytes of working area" idea. Other ideas or opinions? Separately, injection_points_cleanup() breaks the rules by calling InjectionPointDetach() while holding a spinlock. The latter has an elog(ERROR), and reaching that elog(ERROR) leaves a stuck spinlock. I haven't given as much thought to solutions for this one. Thanks, nm