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.96) (envelope-from ) id 1wZ8Pw-000nhs-2N for pgsql-bugs@arkaria.postgresql.org; Mon, 15 Jun 2026 14:36:00 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wZ8Pv-00CNEG-1f for pgsql-bugs@arkaria.postgresql.org; Mon, 15 Jun 2026 14:35:59 +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.96) (envelope-from ) id 1wZ8Pv-00CNE8-0r for pgsql-bugs@lists.postgresql.org; Mon, 15 Jun 2026 14:35:59 +0000 Received: from mail-ed1-x52b.google.com ([2a00:1450:4864:20::52b]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wZ8Pt-00000000UNj-2Z8O for pgsql-bugs@lists.postgresql.org; Mon, 15 Jun 2026 14:35:58 +0000 Received: by mail-ed1-x52b.google.com with SMTP id 4fb4d7f45d1cf-68b90fc6a1dso6696708a12.1 for ; Mon, 15 Jun 2026 07:35:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1781534156; cv=none; d=google.com; s=arc-20240605; b=FADEEftnSj8o7l5U32HIYc2/gRAZ9mfhXcUdIGrOMF/5ahw1Xb5PkZKfKB0/aSWZkG sYdXw2TqoehI9X14iU0w1sLGN00GZqUtRAaBJI2gCHJmU+jP0s6aL6ZMkzLQERWyYl3t iW4qUYN7MQOePdNpP5OqzHdu68JOjw5/tvK3OgvrVCLvPo/j1v/8BcILjdOjhKwMISuu sfSCrXMC6ieuZmRvjpMJSwTmYryE3cyW+H0FDWPchmCMuZrUkUe684DGGs+lh4ffM8bX +sulQaIBcJI2IMBBPUS8ua9zjvsoigSRz/OB/S8PjZ8cBBbNH8+LfXEFvcpyKFPd/ypC 5Hfg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=tX/xcgOOb4Jf862exJDZjc1AuZy1b4UhsWZPv5zCnP8=; fh=WbDzb99CJTXCKzN5mkusF6PLl0WWEGUarKdhJtdQkUo=; b=Asyhao9ZJaJZL7hpjAeMSFyiiTI6DA+2fm5cW6jJIhMRMGUrXDB2lAbBTrc5gcXu/9 y7PO2lTWIprDwrluRRUTOMV41Lsx2N5H+37HQPVZbpKxkeYXIBbcLobBHH1N3rXe1Ws6 jbHsAW6KqwOc5Z2GwAmOl2FZj3USVcAGKmMY6uKvH1OTKrxINLk2MNtGKYTSH/RI5sh9 rwcbTx/Cm3HDkNbyzFhDaejPsDrpBnRe/+XzTR6X7uJE7K9xP+AFhJngJ5TEVP+v4LyQ /AaSW8oAgAKw7Z5snNS/l9zK1L0HiCs2s8bsPq3eYhJRkJXtH1NvqisIGqh7wF4iVbGH BEXw==; darn=lists.postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1781534156; x=1782138956; darn=lists.postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=tX/xcgOOb4Jf862exJDZjc1AuZy1b4UhsWZPv5zCnP8=; b=Nf1z3puLoX7m/4MWORds7wG7RzF2+mOflnfhgOQIXki+PMPAaqt1oXHw5cl61xkM4t DnjpiTIF7W3w0kuxVInVKE0eTohSGH2PmUq3+kVeEpvcF1cP/GoerogxriJTH0+5YO2c c1wsPqyOheDskZofPYDp+hiaESigJJD/VAmUzNn5x/J75BDeYn/xHGFRj4nvitdTUeCY zVIKhs6v81sezAbnMfNSxWp28eF/T93RlZwGZsBP3vl5ef8DYQY4Vpss1CHJcRJhywvt E7RZ7OVG4jMi7fp2K8fPtw5pjqaXpTtKNT289n1DKi3ci5XPJq06DhN6fFq1x179OmWS d5gA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781534156; x=1782138956; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=tX/xcgOOb4Jf862exJDZjc1AuZy1b4UhsWZPv5zCnP8=; b=qk824kLvnHr8RTH1iegGnfMqY2KpC081ZOH7YBvWJFXpwOxAh86ECVvvaBdTJguUiR Lh9bgRU4VQMTVK9WFdglnwn8sqi/gO/3v8ktdmyebDJ5Qrxdn2r10sZSaH4mkAektjHV utCnFj2ZwNCyuznMp70ZI+g69wExhvVRyUlrvaMN97r+5ufK3jAR+nm6YaxCe4BdRcZV GuTWms/86YmAUEo0RmDsKb1Y36oenISUkmNfOGLnDppMFhGhfzL7wJ8+gnB0lBLbVpN6 W4bs2B3ETn1ZG0EO2J1omOJ0Q+hNW/kK4C6+C/MSop82gjlDLVS0+Phvj2ckXX3mYzIq UUOw== X-Forwarded-Encrypted: i=1; AFNElJ/+szxcOWIbtWliozhFCBdwbBzAJ4WtqrU+a4lvrK//Iv+ZC75n8BN+yDhYjqLkoKr9GpMs+xy2gEIx@lists.postgresql.org X-Gm-Message-State: AOJu0YybcS8DuLF4zSr89sHoa30U8uKe9SIsDy1zys04zpOxxGTJMvlP r3com2eFWvq5XODUi1sP7ks/q4fpUyDiIFpXFL31bdAZ2ghG7/TvqtSfxVFOcMGed82+DGRfdiF uzgYnHvvTeuhEI/6s1qW9/GcsY/fJuRU= X-Gm-Gg: Acq92OEs4YZz/2kbWuKSVknBPhZk+OZaygix1HgTkUprXHsaoigkMq96Kmn4KVaabzL Vebw1k7ai9u0HkBrdczQ42CDCyIaWGw6Q0zO0uQSWkprHDrtkiKLHVEHQyg0Ao8LcPH0rg/VLbM h8zspm3SSZT4/MbpqPKd7nTuxfT/RwsYg71AOblgXep9zsQfPB89Bns13m5qWE3Z7JkhUGR/zZ+ XlH+CNQYim8kgHftX0nM5xu/k6QEZbMVtaPSG/KhJwMDlpkVVq2W39wDyvuZg39RAxcogZxBZAD iDqhG7T6QgsVNnuSDjRlKkD5u4buHYePaFrrzvUAIDIOpVBq4UAz3oxrg+6Vlw5uULbHURohJdX VKeWlOFwm X-Received: by 2002:aa7:de16:0:b0:687:fc0:8298 with SMTP id 4fb4d7f45d1cf-69369d7baa2mr4196190a12.15.1781534155403; Mon, 15 Jun 2026 07:35:55 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Melanie Plageman Date: Mon, 15 Jun 2026 10:35:43 -0400 X-Gm-Features: AVVi8Cd7UZmoSUH-Tcinr0Eo4YRlJMojW9lRLodt30KKekjHIQzdd8oRz1Qh0n0 Message-ID: Subject: Re: Autoprewarm workers terminated due to a segmentation fault To: Tomas Vondra Cc: Matheus Alcantara , Glauber Batista , pgsql-bugs@lists.postgresql.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Thu, Jun 11, 2026 at 10:40=E2=80=AFAM Tomas Vondra wro= te: > > After looking a bit closer, I think this bug was introduced by > > commit 6acab8bdbcda735ef47b1bb0ba2284d6c465cd88 > Author: Melanie Plageman > Date: Fri Apr 4 15:25:27 2025 -0400 > > Refactor autoprewarm_database_main() in preparation for read stream > > which happens to advance to the next block in a couple places > > blk =3D block_info[++i]; > > before we know it the incremented "i" is a valid element. The following > commit (d9c7911e1a5f adding the read stream) ends up doing the same > thing, except the index is incremented in a callback. > > Melanie, do you agree with the proposed fix? Thanks all for investigating this! I agree that the proposed fix is correct (both v1 and v2). I am a bit torn between the two versions. v1: i =3D p.pos; if (i >=3D apw_state->prewarm_stop_idx) break; blk =3D block_info[i]; preserves what I had intended in that it sets blk as close to where i was advanced as possible. I had wanted this behavior because we have the "fast-forwarding" that happens in a few places in that loop, and I was afraid it would get quite confusing. The other thing I wanted was the invariant that blk is always the i'th block when exiting the loop. This was in case future code restructured the outer loop and added other break conditions and then used blk. However, I do hate duplicating the loop bounds checking in two places. And future code that restructures the control flow of this function is going to have to be extremely careful anyway. The combination of multiple nested loops, "fast-forwarding" behavior, and skipping forward X number of blocks with the read stream made the requirements of this function's control flow quite complex. v2: while (i < apw_state->prewarm_stop_idx) { ForkNumber forknum; BlockNumber nblocks; struct AutoPrewarmReadStreamData p; ReadStream *stream; Buffer buf; blk =3D block_info[i]; /* Stop when we reach a different relation. */ if (blk.tablespace !=3D tablespace || blk.filenumber !=3D filenumber) break; has the advantage that we set blk directly before using it instead of at the end of the previous iteration, which people may find less confusing. So, overall, I am fine with either approach. Whatever other hackers find more clear is the right approach. In my attempt to make it clear, I obviously made it incorrect -- which is far worse :) - Melanie