Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hviY0-0000Ym-W0 for pgsql-bugs@arkaria.postgresql.org; Thu, 08 Aug 2019 13:33:41 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hviXz-0001sj-Nt for pgsql-bugs@arkaria.postgresql.org; Thu, 08 Aug 2019 13:33:39 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hviXz-0001sc-EL for pgsql-bugs@lists.postgresql.org; Thu, 08 Aug 2019 13:33:39 +0000 Received: from mail-lj1-x243.google.com ([2a00:1450:4864:20::243]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hviXw-0002qj-KD for pgsql-bugs@lists.postgresql.org; Thu, 08 Aug 2019 13:33:38 +0000 Received: by mail-lj1-x243.google.com with SMTP id v24so89075812ljg.13 for ; Thu, 08 Aug 2019 06:33:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language; bh=ljyBBUGiFDkGtkUsDQoTki1wdM9MY9noumFKkZDTUNA=; b=WDr4Iw15Lo0gQWlnJmVOen/5ojksemHq2Z9sn9Ez7TBTCDCIA/LKqhtQGBZtCDJg9n iwmKnRjjjybkZqSACZ9PmOTQg47qGR0XSXNL6uzS74pv6etfg+RlXV8dxIUvc3jqfkr0 mmk6dE31XRzmB7VGRTWTife0vLSINMxySaGnstCne7w96gT9m2HoDH+bFG8wPTYSR0PP f+/ebgUeOXuYAdycOY6kxFac1xmV8hDMxMa0Nn98uBBGuPEBKaH/RTyKqOhj4cQ0hR+d ts5Stm7Dh4N3HQ4LMUebYW6Wibnje9WFbb6DWY6l6XKQhX/jhRMsRSHyqNp4wtHaCl09 izWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language; bh=ljyBBUGiFDkGtkUsDQoTki1wdM9MY9noumFKkZDTUNA=; b=IpiPypcn5FpA0O7T6pxHO0Pwx/N9ub6ZeUI1k8cOFX6bZGSFYvBGUfifKfvaem6uro OeQBwCVAt/xrlEgJtVA0xbSpt7GPJJcsbOfm9qweLFJ/gVvNvW8ngoTLsuC+V8bKVk5L h0D1YhlI84wu1yVa3gsTprjY9wgBObFzKXQiaskcBmhwWH17FGh1sHwvflmMmVoRBMnq LLHB9vjwH1YhVzL0yhkbMjYWPYUJO7ccZYA7eSTG16FBFxwwbkqyajOdi8wUY0inxvr6 0l1WeYn7tUJ7Bc83wVCMoKyN4BRMjEMuyoeFrymEjivrrmS7l7VD+2AZtcF9oT36BDOM 411g== X-Gm-Message-State: APjAAAVubyCSYpdprCVFa0JG73wam6Fb6Ketg93X1mU1S5bpitRp4P22 g2uZUcv8H9k+asCvtGgMOgk= X-Google-Smtp-Source: APXvYqzAGPWGsL+jqscW6MAMsmpVxK18gY796pFmWyVB+wKIUYV34zLcaZ6H73IYh6nCCfKGGVUKzQ== X-Received: by 2002:a2e:9bc6:: with SMTP id w6mr8452881ljj.156.1565271215522; Thu, 08 Aug 2019 06:33:35 -0700 (PDT) Received: from [1.0.0.7] ([178.155.4.70]) by smtp.gmail.com with ESMTPSA id b20sm2538453lfc.17.2019.08.08.06.33.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 Aug 2019 06:33:34 -0700 (PDT) Subject: Re: BUG #15943: Valgrind-detected error in SlruPhysicalWritePage To: Andres Freund , pgsql-bugs@lists.postgresql.org, PG Bug reporting form References: <15943-c7232c75bb276d6c@postgresql.org> <902AFCEA-F078-4D47-AF53-1D2FD3022657@anarazel.de> From: Alexander Lakhin Message-ID: <8c31c946-f2e8-3b07-3191-9f5698e3dd14@gmail.com> Date: Thu, 8 Aug 2019 16:33:33 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.2 MIME-Version: 1.0 In-Reply-To: <902AFCEA-F078-4D47-AF53-1D2FD3022657@anarazel.de> Content-Type: multipart/mixed; boundary="------------8E2D929C3F561F0F76D3E49E" Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This is a multi-part message in MIME format. --------------8E2D929C3F561F0F76D3E49E Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Hello Andres, 08.08.2019 13:33, Andres Freund wrote: > Hi, > > On August 8, 2019 12:44:43 AM EDT, PG Bug reporting form wrote: >> The following bug has been logged on the website: >> >> Bug reference: 15943 >> Logged by: Alexander Lakhin >> Email address: exclusion@gmail.com >> PostgreSQL version: 12beta2 >> Operating system: Ubuntu 18.04 >> Description: >> >> When running under valgrind (sitting on the master branch): >> printf "SELECT pg_notify('notify_async1',NULL); %.0s" `seq 2048` | psql >> > That seems likely to be padding. Probably easier to see if you enable read-var-info and track-origins. > With "--track-origins=yes --read-var-info=yes" I get: ==00:00:00:30.800 24110== Syscall param write(buf) points to uninitialised byte(s) ==00:00:00:30.801 24110==    at 0x5054281: write (write.c:27) ==00:00:00:30.801 24110==    by 0x2687F0: SlruPhysicalWritePage (slru.c:851) ==00:00:00:30.801 24110==    by 0x268E95: SlruInternalWritePage (slru.c:543) ==00:00:00:30.801 24110==    by 0x2690F1: SlruSelectLRUPage (slru.c:1095) ==00:00:00:30.801 24110==    by 0x269777: SimpleLruZeroPage (slru.c:269) ==00:00:00:30.801 24110==    by 0x31DABA: asyncQueueAddEntries (async.c:1381) ==00:00:00:30.801 24110==    by 0x31F130: PreCommit_Notify (async.c:845) ==00:00:00:30.801 24110==    by 0x273C19: CommitTransaction (xact.c:2128) ==00:00:00:30.801 24110==    by 0x274A10: CommitTransactionCommand (xact.c:2921) ==00:00:00:30.801 24110==    by 0x53BD7D: finish_xact_command (postgres.c:2597) ==00:00:00:30.801 24110==    by 0x53E2F3: exec_simple_query (postgres.c:1256) ==00:00:00:30.801 24110==    by 0x540545: PostgresMain (postgres.c:4256) ==00:00:00:30.801 24110==  Address 0xf4f95bf is in a rw- anonymous segment ==00:00:00:30.801 24110==  Uninitialised value was created by a stack allocation ==00:00:00:30.801 24110==    at 0x31D967: asyncQueueAddEntries (async.c:1306) and ==00:00:00:48.177 24110== Syscall param write(buf) points to uninitialised byte(s) ==00:00:00:48.177 24110==    at 0x5054281: write (write.c:27) ==00:00:00:48.177 24110==    by 0x2687F0: SlruPhysicalWritePage (slru.c:851) ==00:00:00:48.177 24110==    by 0x268E95: SlruInternalWritePage (slru.c:543) ==00:00:00:48.177 24110==    by 0x26A1BD: SimpleLruTruncate (slru.c:1234) ==00:00:00:48.177 24110==    by 0x31D5A5: asyncQueueAdvanceTail (async.c:2024) ==00:00:00:48.177 24110==    by 0x31F231: ProcessCompletedNotifies (async.c:1132) ==00:00:00:48.177 24110==    by 0x5403D1: PostgresMain (postgres.c:4176) ==00:00:00:48.177 24110==    by 0x4B16D9: BackendRun (postmaster.c:4431) ==00:00:00:48.177 24110==    by 0x4B481B: BackendStartup (postmaster.c:4122) ==00:00:00:48.177 24110==    by 0x4B4B32: ServerLoop (postmaster.c:1704) ==00:00:00:48.178 24110==    by 0x4B5F70: PostmasterMain (postmaster.c:1377) ==00:00:00:48.178 24110==    by 0x406428: main (main.c:228) ==00:00:00:48.178 24110==  Address 0xf4fb5bf is in a rw- anonymous segment ==00:00:00:48.178 24110==  Uninitialised value was created by a stack allocation ==00:00:00:48.178 24110==    at 0x31D967: asyncQueueAddEntries (async.c:1306) Indeed, "memset(&qe, 0, sizeof(qe));" added in the beginning of asyncQueueAddEntries fixes the issue. More interestingly, "memset(qe.data, 0, sizeof(qe.data));" in the same place fixes it too (the patch is attached). So it seems, the padding in AsyncQueueEntry has an alibi. Best regards, Alexander --------------8E2D929C3F561F0F76D3E49E Content-Type: text/x-patch; name="asyncQueueAddEntries-memset.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="asyncQueueAddEntries-memset.patch" diff --git a/src/backend/commands/async.c b/src/backend/commands/async.c index 6e9c580ec6..663d18d61f 100644 --- a/src/backend/commands/async.c +++ b/src/backend/commands/async.c @@ -1310,6 +1310,8 @@ asyncQueueAddEntries(ListCell *nextNotify) int offset; int slotno; + memset(qe.data, 0, sizeof(qe.data)); + /* We hold both AsyncQueueLock and AsyncCtlLock during this operation */ LWLockAcquire(AsyncCtlLock, LW_EXCLUSIVE); --------------8E2D929C3F561F0F76D3E49E--