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 1wXgaM-003PsW-2H for pgsql-bugs@arkaria.postgresql.org; Thu, 11 Jun 2026 14:40:46 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wXgaL-00GHKN-1y for pgsql-bugs@arkaria.postgresql.org; Thu, 11 Jun 2026 14:40:45 +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.96) (envelope-from ) id 1wXgaL-00GHKD-0m for pgsql-bugs@lists.postgresql.org; Thu, 11 Jun 2026 14:40:45 +0000 Received: from relay8-d.mail.gandi.net ([217.70.183.201]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1wXgaG-00000002Ywx-3qQH for pgsql-bugs@lists.postgresql.org; Thu, 11 Jun 2026 14:40:43 +0000 Received: by mail.gandi.net (Postfix) with ESMTPSA id AAEE93F5E4; Thu, 11 Jun 2026 14:40:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vondra.me; s=gm1; t=1781188839; 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: in-reply-to:in-reply-to:references:references; bh=IUxnSAxH3o/o+QSvES/thr9W1Uy6WRNwLez8jtRT17I=; b=EsLVp3TghvHMDQ9Y1Q8GiB6PW2wQhbVnZWF+N3n3+ia64Z40g5LJ2TYj6RgD6WrtJtL2ht zNOZd12ikU/nJJAjcDs3jKI8HYZTMfmpKZZOidcuAJzVP+yY207XIXGb1zGsi1jKH7yQXN CUtUmNVonbSN4SVLI6c8nyHX3v96YT7fBqkD88ovtrK9BNRT2/MsiDJoiJxK10xVvodmrO qFU3AbigssUhrYWGVUn+2Sdk1bJ/gBbJSbQPQ1FJz/8bGx9ci5Ma+48X/lxI8ltwZQvnzW VapdYQX6xfMnhgR1wFlUVFnGlicoZ5P6ZA7aHFwxRgC18ibufusEpqiRp2eBhw== Message-ID: Date: Thu, 11 Jun 2026 16:40:37 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Autoprewarm workers terminated due to a segmentation fault To: Matheus Alcantara , Glauber Batista , pgsql-bugs@lists.postgresql.org, Melanie Plageman References: Content-Language: en-US From: Tomas Vondra In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-GND-Sasl: tomas@vondra.me X-GND-Score: -100 X-GND-Cause: dmFkZTGn2GUyKVrh29XGuIAl7DDGFS9Wiv5O6rO01h6puSkaTK9RPbOUtAG3CgfSCjTUP1EeNgkiTzF+j53rLx5qheOWGlveijs5vLd+JWZPjj6zhV8i4P89Uh8vpk/Wl0PatpJuMsbYc9JTjxCdb5Bi1kNvsiZaNIEF1+5+GiQ3Elq/OvtX8OvnbDWTvYRV895cnzFwqAO5N/2DUwQq1Yt2XoafXCqRRLDIpJzvqZ2QdUE+W570ejJ+0tqjUeMxqhcFx/WgatjvJnar/XdjGqQNglUSlnHkkSUJ9nD9lLfufEckeE70/vCg7GjAEOA64JjCHfLRIqLitO9TEo/OjPY9z+PBY2ZZAx25XvTFSCOoA3iUpUJQ5XXlt0B3qiJ+4Spzhf5V5+8Gz6966gXogjFCkEdWR80nvB32fXwHhGNIbtWidwVcG1bykxmSLhCwtXIFfs3lwxtkhZeQEmY6ZBLMZ9fYA+AaQa9F2ygkKt4I4SfX1g5DIRCxhURAHYOiXenPIJWOR46+9b2JLoynOqBVJnK6jqn7jlQ6vp4A+W4VagNZxJaSVoQojuOsthUB6V5wvSsdZpZR/WYXSpohwVdAIRPcNJok4u/VMZThpfRGOWbeZ2UFOa1tmh+sUNtl1xEchJBuf5PZHKjQRBOd0BG8vjz6ox5ALKwhOGurw2Efi/6SLw X-GND-State: clean List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 6/10/26 00:25, Matheus Alcantara wrote: > On Tue Jun 9, 2026 at 6:44 PM -03, Tomas Vondra wrote: >> So how does it get advanced past the prewarm_stop_idx? I've been unable >> to reproduce it locally, maybe it's platform-specific. The original >> report was from ARM, are you on ARM too, Matheus? >> > > Yes, I'm also on ARM. I also set pg_prewarm.autoprewarm_interval=10s on > postgresql.conf, not sure if it make more easier to reproduce. > >> But AFAIK the code may not account for read stream callback updating the >> pos to prewarm_stop_idx? The callback may end with (p->pos = >> apw_state->prewarm_stop_idx), and that seems to be past the end of the >> array. >> > > Yes, this is my understanding. > >> That'd mean the proposed check is generally the correct way to fix this. >> TBH it's not clear to me why this needs to set the *next* entry at the >> end of the loop. Well, it does that so that the loop condition can use >> 'blk', but that seems a bit fragile / confusing, and no one noticed the >> issue. >> >> Maybe this would be a better way to write the while loop? >> >> while (i < apw_state->prewarm_stop_idx) >> { >> blk = block_info[i]; >> >> if (blk.tablespace != tablespace || >> blk.filenumber != filenumber) >> break; >> >> ... >> } >> >> > > Is attached patch what are you sugesting? If yes, I agree that looks > better, it's more safe and easier to understand. > Yeah, that's roughly what I had in mind. 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 = 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? regards -- Tomas Vondra